Problem getting GPIO to work[solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Problem getting GPIO to work[solved]

Post by ulfh2018 »

I want to use GPIO to turn on some relays and LEDs. I have defined the following in /etc/init.d/domoticz.sh:

Code: Select all

gpio export 4 out
gpio export 14 out

sudo sh -c "echo '1' >> /sys/class/gpio/gpio4/active_low"
sudo sh -c "echo '1' >> /sys/class/gpio/gpio14/active_low"
These devices shows up with index 20 and 26

I have also set up a setpoint and a temperature sensor with index 13 (sensor) and 16 (setpoint)

I want to use gpio 4 (index 20) to control the relay and gpio 14 (index 26) to control a LED.

When I test different values for setpoint, gpio 14 will work, but gpio 4 will not, thoug I can manually switch the value.

I have the created the following script:

Code: Select all

return {
    on = {       timer = { 'every minute'  } },
        execute = function(domoticz)
        local Sensor    = domoticz.devices(13)  -- Temperature
        local SETPOINT  = domoticz.devices(16) -- SetPoint
        SETPOINT.updateSetPoint(SETPOINT.setPoint)  -- This will refresh the setPoint with current value
        if (Sensor.temperature <= (SETPOINT.setPoint - 0.2)) then -- turn on heat   
        domoticz.devices(20).switchOn().checkFirst()
        domoticz.devices(26).switchOff().checkFirst()
        elseif (Sensor.temperature >= (SETPOINT.setPoint + 0.2)) then -- turn off hea
        domoticz.devices(20).switchOff().checkFirst()
        domoticz.devices(26).switchOn().checkFirst()
        else
            -- within hysteresis range
        end
    end
}
Can someone see what I might be doing wrong?

Best regards

Ulf
Last edited by ulfh2018 on Sunday 09 June 2019 7:12, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem getting GPIO to work

Post by waaren »

ulfh2018 wrote: Friday 07 June 2019 20:21 Can someone see what I might be doing wrong?
The dzVents seems OK. Don't understand why you have the 'refresh' line but it should not harm the flow of the code.
Do you see anything in the domoticz log ?
If not; may I suggest to add some log statements in the code ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Problem getting GPIO to work

Post by ulfh2018 »

Hi Waaren
Thank you for having a look!

I found the problem. I had used similar names for some of the devices, when I changed that, everything worked as expected. The name of the sensor and the name of the switch was the same. Stupid me!
I thought the refresh was to avoid the setPoint becoming red after a while, or am I wrong?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem getting GPIO to work

Post by waaren »

ulfh2018 wrote: Friday 07 June 2019 21:41 Hi Waaren
Thank you for having a look!

I found the problem. I had used similar names for some of the devices, when I changed that, everything worked as expected. The name of the sensor and the name of the switch was the same. Stupid me!
I thought the refresh was to avoid the setPoint becoming red after a while, or am I wrong?
Good that you found it and yes the refresh prevent the inactive color to come up.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest