Changing from ESP Easy to local

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:

Changing from ESP Easy to local

Post by ulfh2018 »

I have been able (with a lot of help from you, folks) to configure a system using a Thermostat, a Temp sensor and a switch (in fact, 4 of each, but the it's the same all over. I the temperatur sensors was on ESP8266, and I was using rules to make it work. It work OK, but I have now decided I need to go for manipulating the information from Domotizc local. Reason is problem with network access in the area where this should be implemented, so I have to install the RPi near the relays I want to manipulate and use RFXtrx433XL to receive data from the sensors. I am though still testing using DS18B20 sensors in case I cannot make it work. Don't want to spend too much money on HW - just in case ;)

I have configured GPIO ports on the RPi, and they are vissible in Domoticz as light switches after editing the /etc/init.d/domoticz.sh.

I am using the following VERY SIMPLE script, and there are some things missing

return {
on = { timer = { 'every minute' } },

execute = function(domoticz)
local Sensor = domoticz.devices(8) -- Temperatur
local SetPoint = domoticz.devices(12) -- SetPoint
if Sensor.temperature <= SetPoint.setPoint then
domoticz.devices(11).switchOn()
else
domoticz.devices(11).switchOff()
end
end
}

I am missing three things:

1. How to access the gpio devices from the scipt
2. How to implement hysteresis.
3. How to resend the setPoint. I can do it using two separate scripts, so this is not a major issue :)
Any sugestion is welcome

Best regards

UIf
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Changing from ESP Easy to local

Post by waaren »

ulfh2018 wrote: Wednesday 20 March 2019 12:56 I have configured GPIO ports on the RPi, and they are vissible in Domoticz as light switches after editing the /etc/init.d/domoticz.sh.
I am missing three things:

1. How to access the gpio devices from the scipt
2. How to implement hysteresis.
3. How to resend the setPoint. I can do it using two separate scripts, so this is not a major issue :)
Any sugestion is welcome
Maybe this example script
can help you to implement hysteresis.
What is the effect of switching the lights connected to the GPIO's ?
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: Changing from ESP Easy to local

Post by ulfh2018 »

Thank you so much - again!

I have made a VERY simple script which I have repeated for the 6 rooms I want to control, and hope this is a way I can go. I use the index numbers to address devices, and if I get it right, this example will add hystresis of .4 degrees, which migh be too litle, but can of course be changed.

return {
on = { timer = { 'every minute' } },
execute = function(domoticz)
local Sensor = domoticz.devices(7) -- Temperature
local SETPOINT = domoticz.devices(13) -- SetPoint
SETPOINT.updateSetPoint(SETPOINT.setPoint)
if (Sensor.temperature <= (SETPOINT.setPoint - 0.2)) then -- turn on heat
domoticz.devices(1).switchOn()
elseif (Sensor.temperature >= (SETPOINT.setPoint + 0.2)) then -- turn off heat
domoticz.devices(1).switchOff()
end
end}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Changing from ESP Easy to local

Post by waaren »

ulfh2018 wrote: Tuesday 26 March 2019 13:40 I have made a VERY simple script which I have repeated for the 6 rooms I want to control, and hope this is a way I can go. I use the index numbers to address devices, and if I get it right, this example will add hystresis of .4 degrees, which migh be too litle, but can of course be changed.
Looks OK to me; only thing I would change is to add the method checkFirst() to prevent sending On or Off to the Switch when not needed:

Code: Select all

return {
    on = {       timer = { 'every minute'  } },
  
    execute = function(domoticz)
        local Sensor    = domoticz.devices(7)  -- Temperature
        local SETPOINT  = domoticz.devices(13) -- 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(1).switchOn().checkFirst()
        elseif (Sensor.temperature >= (SETPOINT.setPoint + 0.2)) then -- turn off heat
            domoticz.devices(1).switchOff().checkFirst()
        else
            -- within hysteresis range
        end
    end
}
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: Changing from ESP Easy to local

Post by ulfh2018 »

Perfect!
You ARE a genius!
:)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest