Control remote pi GPIO with domoticz

813 Views Asked by At

There are 2 pi in this setup:
- PI-domo: running domoticz
- PI-pump: controlling a pump with one GPIO

Those pi are far away, but can communicate through network. PI-domo has some passwordless ssh login setup to pi-pump, and contains three scripts:
- pump_on.sh: sends value to gpio with ssh to turn pump on and returns 1

  `ssh pi@pi-pump -n "echo 0 > /sys/class/gpio/gpio18/value" && echo 1`
  • pump_off.sh: sends value to gpio with ssh to turn pump off and returns 0

    ssh pi@pi-pump -n "echo 1 > /sys/class/gpio/gpio18/value" && echo 0

  • pump_status.sh: returns 1 if pump is on, 0 if pump is off.

All three scripts work as expected when launched in bash, but I can not find how to call them with domoticz. I created a virtual switch and set those as script:///.....[on off].sh but domoticz doesn't seem to be running any of them. nor could I find a place to read the status...

Any idea or link to a RECENT (working) tutorial would be welcome!

2

There are 2 best solutions below

0
On

I know that this is a old thread and it is answered already, but I have stumbled on the same issue and found that online answers lacked detail. So, here it goes:

  1. On PI-domo run sudo su to become root
  2. Generate a new key using ssh-keygen -t rsa -b 4096 -C "nameofyourkey"
  3. Copy your key to PI-pump by using ssh-copy-id -i /root/.ssh/yourkey.pub pi@pi-pump
  4. ssh to pi-pump to test that ssh agent for root is working, and if all is well exit and go back to become a pi user.

Note 1: Although logging in as root of PI-domo, it is critical that pump_off and pump_status.sh contain pi@pi-pump and not root@pi-pump or this approach will fail.

Note 2: Domoticz log indicates that the above process has some error by outputting Error: Error executing script command (/home/pi/domoticz/scripts/pump_off.sh). returned: 65280. Note the 65280 error in particular

0
On

Found the issue: stupid me.
It turns out domoticz process was running as root and root didn't have the key setup for passwordless ssh.