logo elektroda
logo elektroda
X
logo elektroda

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

Daro1003 306 16
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21366307
    Daro1003
    Level 33  
    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.
    Do you have a problem with Raspberry? Ask question. Visit our forum Raspberry.
  • ADVERTISEMENT
  • #2 21373958
    michal.zd
    Level 28  
    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 33  
    michal.zd wrote:
    Check in the settings of domoticz.


    Where can I find this ?
  • #4 21374035
    michal.zd
    Level 28  
    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
  • #5 21374065
    Daro1003
    Level 33  
    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.
  • ADVERTISEMENT
  • #6 21374079
    michal.zd
    Level 28  
    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.
  • #7 21374134
    Daro1003
    Level 33  
    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 28  
    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 😉.
  • ADVERTISEMENT
  • Helpful post
    #9 21403384
    michal.zd
    Level 28  
    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 33  
    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 28  
    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 33  
    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. .
  • ADVERTISEMENT
  • #13 21405268
    michal.zd
    Level 28  
    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 33  
    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.
  • Helpful post
    #15 21405280
    michal.zd
    Level 28  
    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 28  
    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.
Summary generated by the language model.
ADVERTISEMENT