logo elektroda
logo elektroda
X
logo elektroda

Raspberry Pi 3B+ with Domoticz - how to maintain GPIO state after reboot?

Daro1003 1107 16
Best answers

How can I make Domoticz restore and keep the Raspberry Pi GPIO output active after a reboot or power loss?

Make Domoticz start only after the GPIO system is ready, because the thread suggests Domoticz comes up before the kernel/module handling the Raspberry Pi ports, so it remembers the switch state but the GPIO pin is still inactive [#21373958] Disable the Domoticz service autostart with `sudo systemctl disable domoticz`, reboot, and then start it manually with `sudo systemctl start domoticz` to verify that the GPIO state is applied correctly after boot [#21374035] If that fixes it, configure the Domoticz systemd service to start later at boot or add an appropriate delay/dependency in the service file, which should be in `/etc/systemd/system` or another Domoticz service unit location [#21373958][#21374035]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21366307
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    Hello

    I have a Raspberry 3B+ with an SSD on which is domoticz.

    To the GPIO of the Raspberry connected the input of the Integra which informs the Integra about sunset and sunrise. That is, after sunset activates the GPIO which violates the input on the Integra.

    The problem is that e.g. after a power loss and after the Raspberry comes back to life in domoticz, the corresponding switch is active - on, so it looks like it's ok. Domoticz remembers the state, but GPIO on the Raspberry board is not active, so it doesn't interfere with the input in the Integra.

    How to solve this ? Dismiss GPIO and connect some other device e.g. sonoff which will remember the state after restart ??
    I thought that the GPIO control would be the most stable in operation because without intermediate devices.
  • ADVERTISEMENT
  • #2 21373958
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    Daro1003 wrote:
    on, so it looks like domoticz has memorised the state but the GPIO on the raspberry board is not active
    .
    Looks like domoticz is starting earlier than the kernel module responsible for handling the ports.
    Check in the settings of the domoticz service.
    Any such client service preferably starts last.
    You can try to disable domoticz autostart and start manually after booting.
  • #3 21373979
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    michal.zd wrote:
    Check in the settings of domoticz.


    Where can I find this ?
  • #4 21374035
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    First check that manually starting domoticz will work correctly.
    Disable it with the command sudo systemctr disable domoticz. After reboot, start it with the command systemctr start domoticz.
    The enable option will again cause it to autostart on boot.
    I don't have domoticz, but all services have configuration files in the /etc/systemd/system directory,
    there is plenty of that, there must be a file for domoticz somewhere too. But how to delay it look on the domoticz forum. If you find a domoticz configuration file, search under
    debian systemd service delay
  • ADVERTISEMENT
  • #5 21374065
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    I'm connecting the Raspberry to a buffer power supply so short outages will be out of the question and I'll probably leave the topic as I know it's not that simple.
    By the way, I think I have to leave domoticz already and switch to HA. It has a lot done to it, but to make it all work perfectly I would not say so.
  • #6 21374079
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    Daro1003 wrote:
    knows it's not that simple
    .
    Simple, just need to find that service configuration file.

    Added after 1 [minute]: .

    Daro1003 wrote:
    You probably need to leave domoticz
    .
    That's acutely true, a mare and not much can, like an old nag.
    Ps. Have you tried node-red? You once asked me how to install it.
  • ADVERTISEMENT
  • #7 21374134
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    michal.zd wrote:
    Ps. Have you tried node-red? You once asked me how to install.
    .

    Nothing lies all but the topic of Sofar integration with domoticz topical and even reheated because needed data for control.
  • #8 21374190
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    Daro1003 wrote:
    the topic of Sofar integration with domoticz
    .
    I replied in the SmartnyDom forum, but we can move to elka.
    Domoticz from mosquitto server can read, do you need nodered?

    Back to the topic of installing node-red on rpi, I just installed on rpi zero W before Christmas, it went without a problem according to this description
    https://nodered.org/docs/getting-started/raspberrypi
    bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
    .
    A little lick of the Linux console you have to 😉.
  • Helpful post
    #9 21403384
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    Returning to the topic inverter -> broker -> mosquitto -> domoticz....
    Running the broker gives access to the data from the inverter for the mqtt server. But whether domoticz itself is able to receive it from the mosquitto server I don't know. I use node-red, everything is possible there.

    When you run 'screen' then on the virtual console run my broker, let it work, as I gave in the pw:
    screen -S pvb
    cd /usr/pv
    sudo ./inverterbroker --d let it work there
    ps. the --d parameter means to send information to the terminal, it is for the control of the operation, without the parameter there will not be these data from the inverter on the screen.
    The mqtt data is always sent

    then open putty another terminal and in it:
    mosquitto_sub -h localhost -v -t ime/#

    you'll see what data I'm sending with the mqtt protocol. There should be something like this:
    
    ime/inverter/state S17, P 00, Avg 50
    ime/inverter/json { "Time":"16:31:32","Day":2, "State":17,"P":0,"Avg":50, "Grid":{"U":[0,0,0], "AvgU":[2070,2070,2070], "I":[0,0,0],"MaxU":2279,"L":16,"OV":0}}
    ime/inverterdata ▒
    
    .

    just now it's dark and the inverter has switched off, hence "State":17 - no connection, but the json elements are visible. Subsequent topics:
    ime/inverter/state state in text form
    ime/inverter/json json for node-red, it is possible that this can be used for domoticz, an expert in it would have to say.
    ime/inverterdata the same as json, but in binary form, a ready-made data structure for your own control programs.

    Information for others.
    The topic hooks up to my broker program between inverter and mqtt server. written in C for raspberry pi. It retrieves data from the inverter via the WiFi Logger LSW-3.
    Sources and binaries for ARM11 single core processor and Cortex-A53 quad core processor at :
    https://github.com/michalzd/pvInverterBroker/tree/mqtt
    you will also need the mqtt library: https://github.com/michalzd/MQTT_LinuxLib

    Thanks to @Daro1003 we tested with him on a Raspberry Pi3+ and with a Sofar HYD15-KTL. Mine is a Sofar KTL-X G3 and a Raspberry 1B.
    It is likely that the whole Sofar KTL family will have the same specification of port addresses accessible via ModBus. You might be tempted to pull storage data from the hybrid, as that's there too, but debugging/testing remotely is a bit difficult.
  • #10 21403730
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    My progress is:

    1. installed screen
    sudo apt install screen
    .
    2. i ran
    screen -S pvb 
    .
    3. I ran from the /usr/pv directory
    inverterbroker --d
    .


    Terminal screen with InverterBroker running and PV data displayed. .

    4. now if I fire up after turning on putty
    screen -r pvb
    .
    Then I have the data immediately:

    Screenshot of a terminal displaying photovoltaic panel data. .
  • Helpful post
    #11 21404832
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    michal.zd wrote:
    then open putty another terminal and in it:
    mosquitto_sub -h localhost -v -t ime/#
    .
    Now here see the data that comes into mosquitto.
  • #12 21405255
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    michal.zd wrote:
    michal.zd wrote:
    then open putty another terminal and in it:
    mosquitto_sub -h localhost -v -t ime/#
    .
    Now here see the data that comes into mosquitto.


    Exactly the data is flying:

    Screenshot displaying MQTT message data about an inverter's status.

    Console screenshot with JSON data related to inverter status. .
  • #13 21405268
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    Great, so the communication is there. Now there are two things left to do.
    1. run the broker as a service, I will give the service configuration file later.
    2. read the data in domoticz, possibly in node-red.

    Added after 1 [minute]: .

    Just something power some great. What is the broker showing? Although if the State is greater than 0, the inverter can pass on nonsense.
  • #14 21405270
    Daro1003
    Level 34  
    Posts: 2709
    Help: 295
    Rate: 603
    Board Language: polish
    michal.zd wrote:
    2. Read the data in domoticz, possibly in node-red.
    .

    Unfortunately I do not have node-red and this is also a topic that fits in the future to move supposedly a lot there.
  • ADVERTISEMENT
  • Helpful post
    #15 21405280
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    Daro1003 wrote:
    much can be done there.

    Yes, you just need to delve into the subject of JavaScript objects and json.
    A little tutorial:
    https://noderedguide.com/
  • #17 21419537
    michal.zd
    Level 31  
    Posts: 1603
    Help: 83
    Rate: 262
    Board Language: polish
    If node-red has a problem during installation, the node.js version is usually affected.
    It is written in this manual
    if it detects Node.js is already installed, it will ensure it is at least v14. If less than v14 it will stop and let the user decide whether to stay with Node-RED version 1 - or upgrade Nodejs to a more recent LTS version. If nothing is found it will install the Node.js 16 LTS release using the NodeSource package.
    
    Running Node-RED install for user pi at /home/pi on raspbian
    
    Node-RED v3.x no longer supports Nodejs 10
    
      You can force an install of node 18 or 20 by adding --node18 or --node20 to the end of the command line above...
      Exiting now.
    
    .

    Then:
    
    bash <(curl -sL  https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)  --node18
    .

Topic summary

✨ A Raspberry Pi 3B+ running Domoticz with an SSD is used to control GPIO pins connected to an Integra system for sunset and sunrise signals. After power loss and reboot, Domoticz retains the switch state, but the Raspberry Pi GPIO pins do not maintain their active state, causing a mismatch with the Integra input. The main issue is that Domoticz starts before the kernel module managing GPIO, leading to GPIO pins not being set correctly on boot. Suggested solutions include delaying Domoticz service startup via systemd configuration to ensure kernel modules load first, manually starting Domoticz after boot, or considering alternative devices like Sonoff that retain state after reboot. The discussion also touches on integrating MQTT brokers (Mosquitto) and Node-RED for advanced control and data handling, with advice on installing Node-RED and managing Node.js versions. The user contemplates switching from Domoticz to Home Assistant for better stability and functionality.
Generated by the language model.

FAQ

TL;DR: To keep Raspberry Pi 3B+ GPIO states after reboot in Domoticz, apply a 3-step service‑delay fix; "Any such client service preferably starts last." Use systemd to start Domoticz after GPIO is ready. [Elektroda, michal.zd, post #21373958]

Why it matters: This FAQ helps Domoticz-on-Raspberry-Pi users stop the "On in UI, Off on GPIO" mismatch after reboots or brief outages, including security setups with Integra.

Quick Facts

Why do my Domoticz switches look On after reboot but the GPIO pin is Off?

Domoticz saves UI state, but GPIO reinitializes during boot. Start-order causes the mismatch. “Looks like domoticz is starting earlier than the kernel module responsible for handling the ports.” Delay Domoticz so it starts after GPIO is ready. [Elektroda, michal.zd, post #21373958]

How do I delay Domoticz until GPIO is ready with systemd?

Use systemd to adjust start timing. Disable autostart, then edit the domoticz service under /etc/systemd/system to start last, adding a brief delay or dependency. Re-enable autostart after testing. This ensures Domoticz initializes GPIO only after the system is ready. [Elektroda, michal.zd, post #21374035]

How do I confirm start-order is the problem?

Do this quick test:
  1. Disable autostart: sudo systemctl disable domoticz.
  2. Reboot, log in, and check GPIO remains idle.
  3. Start Domoticz: sudo systemctl start domoticz; verify the GPIO toggles correctly. If manual start fixes it, set a delayed service start. [Elektroda, michal.zd, post #21374035]

Where are Domoticz service settings on Raspberry Pi OS?

Service units live in /etc/systemd/system. Look for domoticz.service there. Edit that unit to control dependencies, delays, and start behavior, then reload systemd and test. [Elektroda, michal.zd, post #21374035]

Should I replace GPIO with a Sonoff or other device to retain state?

Not for this symptom. Fixing service order makes GPIO reliable after boot. External devices that retain state can help during long outages, but your direct-GPIO setup remains solid once startup timing is corrected. [Elektroda, Daro1003, post #21366307]

Can Domoticz read MQTT directly, or do I need Node-RED?

Domoticz can read from a Mosquitto server, so Node-RED is optional. Node-RED adds flexible flows, dashboards, and logic if you want more control. [Elektroda, michal.zd, post #21374190]

How do I install Node-RED on a Raspberry Pi?

Use the official install script from the Node-RED Raspberry Pi guide. It fetches Node.js and Node-RED, configures the service, and simplifies updates. Start Node-RED afterward and open the editor in your browser. [Elektroda, michal.zd, post #21374190]

Node-RED install fails due to Node.js version—what should I do?

That error signals an unsupported Node.js version. “Node-RED v3.x no longer supports Nodejs 10.” Re-run the installer with --node18 or --node20 to upgrade and finish installation successfully. [Elektroda, michal.zd, post #21419537]

How do I view MQTT messages from my inverter broker to confirm data?

Open a second terminal and subscribe to the broker. Run: mosquitto_sub -h localhost -v -t ime/#. You should see live topics and JSON payloads if publishing works. [Elektroda, michal.zd, post #21404832]

How can I run the inverter broker persistently on my Pi?

Launch it inside a screen session. Create a session: screen -S pvb. cd to /usr/pv and start: sudo ./inverterbroker --d. The --d flag prints debug; MQTT publishes even without it. [Elektroda, michal.zd, post #21403384]

What does “State 17” mean in the broker output at night?

State 17 indicates the inverter is off or not connected, such as after sunset. JSON structure remains visible, but energy production is idle. [Elektroda, michal.zd, post #21403384]

Why do power values look wrong when State > 0?

During certain states, reported values can be unreliable. When State is greater than 0, the inverter may output misleading numbers. Treat those readings cautiously. [Elektroda, michal.zd, post #21405268]

Will a buffer power supply or UPS solve the GPIO mismatch?

A buffered supply masks short outages, so you see fewer reboots. It does not fix the root cause. Correct Domoticz start timing first, then add power buffering if needed. [Elektroda, Daro1003, post #21374065]
Generated by the language model.
ADVERTISEMENT