Add GPIO state to graph

Is there a way to graph the state of an GPIO output instead of the duration bar?
Like this:

I just added the ability to set each series type (line or column) in the graph widget. It hasn’t been released, so if you want to test, you’ll need to upgrade to master.

hey Kyle, I like your pragmatic way developing mycodo.
This feature draws the duration as a line. But i needed the state.

Background: I have a solar powered aquaponic system. I monitor the level of the buffer battery. At certain level I activate a relay to get power from the grid.
I want to see when (what time) the relay switches to ‘grid power’ and when it came back.

Maybe I could do a hardware solution. Physically connect the output pin to another input pin. Then monitor the state of the second (the input) pin.
Falko

1 Like

You don’t need to connect a GPIO to another GPIO to measure its state, just use the GPIO State Input, which will store 0 (low) or 1 (high).

How do you accomplish the power transfer from solar to the grid? a double-pole double-throw mechanical relay?

No. you can not have an input and an output on the same pin.
I tried :slight_smile:

yes, it’s a DPDT relais. but the setup is a bit more complex.
I have a custom input to monitor all data from a victron solar charger.
I use a bang-bang hysteresis on battery voltage to set an output. The output triggers a solid state relay which switches power supply. The power supply triggers the DPDT relay and powers the pump.

When the battery reaches a higher level the output turns off and all relay fall back to default.

It’s been a long time since I tried. What happens when you do this?

after I activated the input, I went to output page an turned it on.

2022-08-24 17:35:10,010 - INFO - mycodo.controllers.controller_input_730b8339 - Activated in 788.3 ms
2022-08-24 17:36:04,196 - ERROR - mycodo.outputs.on_off_gpio_5805c653 - State change error: The GPIO channel has not been set up as an OUTPUT
Traceback (most recent call last):
  File "/home/pi/Mycodo/mycodo/outputs/on_off_gpio.py", line 172, in output_switch
    self.options_channels['on_state'][output_channel])
RuntimeError: The GPIO channel has not been set up as an OUTPUT

So I think a good addition would be an Output State Input. This would query the output state through Mycodo rather than attempting to set the GPIO as an input (which causes this issue with a GPIO output).

Hmm, yes that would fulfill.
what about, two options to graph an output?
1st duration as float in seconds
2nd state as bool
The indicator widget does the same (just for now).
But this depends on how outputs are stored in the database…
So yes, maybe the Input is more ‘strait forward’.

You can only display measurements on a graph that were stored to the measurement database, and a boolean output values are not stored for outputs. And since you must either 1) periodically store boolean values, or 2) store an additional 0 immediately before storing 1 when the output turns on, for it to be meaningful (otherwise it looks like a mountain rather than a square wave), it adds an additional complexity to changing how all outputs store measurements.

An Input makes the most sense to implement since it doesn’t require altering outputs. Inputs can also be created in a matter of minutes, especially for something as simple as this kind of Input, since all the framework for it to work already exists (simply querying the state of an output and periodically storing the value).

An Input makes the most sense to implement since it doesn’t require altering outputs. Inputs can also be created in a matter of minutes, especially for something as simple as this kind of Input, since all the framework for it to work already exists (simply querying the state of an output and periodically storing the value).

Yes. I totally agree.

But anyway. I like the column option.
My ‘daily solar yield’ graph looks very powerful now :slight_smile:

1 Like

I just committed a new On/Off Output State Input: