State change error after power failure

Hi there

I have a setup running 8 outputs that get controlled by functions.
We experience power failures quite often, which leads to the system shutting down and restarting (probably not a full reboot).
After this the outputs cannot get controlled by the functions… I get the following message:

2021-10-28 11:31:16,599 - ERROR - mycodo.outputs.on_off_gpio_e86004ba - 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 177, in output_switch
not self.options_channels[‘on_state’][output_channel])
RuntimeError: The GPIO channel has not been set up as an OUTPUT

Also, when trying to manually turn the outputs on or off, I get the same message.
The outputs are also not necessary in their default startup state. Regardless of the startup state, they are in whichever state is set with the GPIO giving power.

I have to go onto the outputs and manually save them again to obtain normal functioning… which is problematic as it is not sustainable to do this and in the time when the outputs are out of whack, my room conditions will do the same (for example - heater turns on, humidifier shuts down - when I should be cooling). I know I could rewire them so that everything can be powered down on the startup and at least have a stable state, but…

3 of the outputs seem to work continuously without having to save them. They continue to operate normally straight after the power comes back on without needing to be saved. SO I know it should be possible for the outputs to do this.
I see no difference in my setup between the working and non-working outputs, except that the ones added at a later stage were working correctly.
After this observation however, I deleted all the non-working outputs (which were 6 of them at the time), and added them in again, to find that only one of the newly added ones now function correctly.

Is there anything known that would solve this issue that I can try out? I bit uncertain here…

Thanks in advance

1 Like

The output controller sets all GPIO output pins as OUTPUT upon startup. So, for them not be be set as such would indicate there is an issue with the output controller, you have something else changing them from output to something else, or you are using some strange pins that some other system is interfering with.

You can turn Log Level: Debug on for each output and gain more information in the daemon log about their status. Additionally, is there anything of concern in the daemon log when the output controller is starting up as the first action of the daemon when it starts up?

Thank you for your response.

I will have a look to see what the difference is between the working outputs and non-working ones on the physical GPIO pin connection, as I think it must be that.
Regarding the startup, my log looks like there aren’t any problems…
Please see code below, with debugging also logged.

2021-11-09 08:12:01,760 - DEBUG - mycodo.outputs.on_off_gpio_e86004ba - output_on_off(off, 0, None, 0.0, 0.0, True)
2021-11-09 08:12:01,761 - DEBUG - mycodo.outputs.on_off_gpio_e86004ba - Output e86004ba-2893-4771-8773-22272e8ffad7 CH0 (Cooling pump v2) OFF at 2021-11-09 08:12:01. Output returned: success
2021-11-09 08:12:07,412 - INFO - mycodo.controllers.controller_conditional_c11e88a9 - Measuring room humidity. The value is 92.2
2021-11-09 08:12:07,563 - INFO - mycodo.controllers.controller_conditional_c11e88a9 - Humidifier already off
2021-11-09 08:12:07,563 - INFO - mycodo.controllers.controller_conditional_c11e88a9 - Humidity is right!
2021-11-09 08:12:08,112 - INFO - mycodo.controllers.controller_conditional_a9a75190 - Checking room humidity sensor. The value is 92.2
2021-11-09 10:21:45,147 - INFO - mycodo.daemon - Mycodo daemon v8.12.8 starting
2021-11-09 10:21:47,221 - INFO - mycodo.outputs.on_off_gpio_90af20f8 - Output setup on pin 7 and turned ON (ON=HIGH)
2021-11-09 10:21:47,222 - INFO - mycodo.outputs.on_off_gpio_90af20f8 - Initialized in 485.6 ms
2021-11-09 10:21:47,619 - INFO - mycodo.outputs.on_off_gpio_e04d8268 - Output setup on pin 24 and turned OFF (ON=HIGH)
2021-11-09 10:21:47,620 - INFO - mycodo.outputs.on_off_gpio_e04d8268 - Initialized in 393.8 ms
2021-11-09 10:21:48,030 - INFO - mycodo.outputs.on_off_gpio_ee1a9d84 - Output setup on pin 14 and turned OFF (ON=HIGH)
2021-11-09 10:21:48,031 - INFO - mycodo.outputs.on_off_gpio_ee1a9d84 - Initialized in 406.3 ms
2021-11-09 10:21:48,420 - INFO - mycodo.outputs.on_off_gpio_92c946a1 - Output setup on pin 8 and turned OFF (ON=LOW)
2021-11-09 10:21:48,421 - INFO - mycodo.outputs.on_off_gpio_92c946a1 - Initialized in 385.6 ms
2021-11-09 10:21:48,797 - INFO - mycodo.outputs.on_off_gpio_7c06098d - Output setup on pin 25 and turned OFF (ON=HIGH)
2021-11-09 10:21:48,798 - INFO - mycodo.outputs.on_off_gpio_7c06098d - Initialized in 373.3 ms
2021-11-09 10:21:49,189 - INFO - mycodo.outputs.on_off_gpio_e86004ba - Output setup on pin 23 and turned ON (ON=HIGH)
2021-11-09 10:21:49,189 - INFO - mycodo.outputs.on_off_gpio_e86004ba - Initialized in 387.4 ms
2021-11-09 10:21:49,580 - INFO - mycodo.outputs.on_off_gpio_cafa2b25 - Output setup on pin 15 and turned OFF (ON=HIGH)
2021-11-09 10:21:49,581 - INFO - mycodo.outputs.on_off_gpio_cafa2b25 - Initialized in 387.1 ms
2021-11-09 10:21:49,956 - INFO - mycodo.outputs.on_off_gpio_3703c706 - Output setup on pin 18 and turned OFF (ON=LOW)
2021-11-09 10:21:49,957 - INFO - mycodo.outputs.on_off_gpio_3703c706 - Initialized in 372.7 ms
2021-11-09 10:21:49,958 - INFO - mycodo.controllers.controller_output - Activated in 4029.3 ms
2021-11-09 10:21:51,087 - INFO - mycodo.controllers.controller_conditional_ab596204 - Activated in 161.3 ms
2021-11-09 10:21:51,645 - INFO - mycodo.controllers.controller_conditional_60c75509 - Activated in 150.5 ms
2021-11-09 10:21:52,235 - INFO - mycodo.controllers.controller_conditional_c11e88a9 - Activated in 206.3 ms
2021-11-09 10:21:52,802 - INFO - mycodo.controllers.controller_conditional_ab596204 - Checking room temp. The value is None
2021-11-09 10:21:53,205 - INFO - mycodo.controllers.controller_conditional_a9a75190 - Activated in 142.4 ms
2021-11-09 10:21:53,209 - INFO - mycodo.daemon - All activated Conditional controllers started
2021-11-09 10:21:53,858 - INFO - mycodo.controllers.controller_trigger_f1d69e19 - Activated in 233.7 ms
2021-11-09 10:21:54,780 - DEBUG - mycodo.outputs.on_off_gpio_ee1a9d84 - output_on_off(on, 0, sec, 0.0, 0.0, True)
2021-11-09 10:21:54,781 - DEBUG - mycodo.outputs.on_off_gpio_ee1a9d84 - Output ee1a9d84-87d9-431d-82b6-1862fdb9ef60 CH0 (Lights V2) ON at 2021-11-09 10:21:54.781100. Output returned: success
2021-11-09 10:21:54,928 - INFO - mycodo.controllers.controller_trigger_4868a54d - Activated in 385.4 ms
2021-11-09 10:21:54,937 - INFO - mycodo.daemon - All activated Trigger controllers started
2021-11-09 10:21:56,392 - INFO - mycodo.controllers.controller_input_0af2b21b - Activated in 695.1 ms

Lastly, before the output error as with the first log I sent, I get the following debug message as well.

2021-11-09 07:47:57,462 - DEBUG - mycodo.outputs.on_off_gpio_3703c706 - output_on_off(on, 0, sec, 0.0, 0.0, True)
2021-11-09 07:47:57,463 - ERROR - mycodo.outputs.on_off_gpio_3703c706 - 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 174, in output_switch
self.options_channels[‘on_state’][output_channel])
RuntimeError: The GPIO channel has not been set up as an OUTPUT

I am not sure if that additional debug info is helpful at all.
But will definately check the physical GPIO connections, as I know some are dedicated and some may have other functions, which as you state could be interfering.

Thanks again

So just some more info:
This is the summary of the physical pinout, as well as the startup state.

Output BCM Startup state On state Actual state GPIO type
1 14 OFF High grey
2 7 ON High grey
3 8 OFF Low grey
4 25 OFF High ON green
5 23 ON High green
6 24 OFF High green
7 15 OFF High grey
8 18 OFF Low grey

So I could not find any clear correlation here… Let me know if you see anything.

I have also noticed output one starts up in off state, then gets switched on with the trigger controller successfully, but if I try change it manually it does not change until I save the output again.

Then with output 4, I see if says its starts up in the off state, but then when I go to the outputs page, it shows it is on. I cannot find in my logs where this is actually switched on, I also do not have any controllers controlling this currently, so that is quite strange…

Hope this info sheds some light

Have you switched pins?