noob help needed: If temperature > thermostat then

Moderator: leecollings

Post Reply
jhenrikb
Posts: 26
Joined: Sunday 08 January 2017 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

noob help needed: If temperature > thermostat then

Post by jhenrikb »

Hi!
after figuring out someone of blockly codes are bugging my PI's memory, making it slowly reach 100% then crash, i decided to write all the events in LUA.

After a lot of research, the only thing I have left now is heat-control.
Cant seem to get it to work since I dont know how to write this Blockly image into LUA code.

if (devicechanged['tempsensor goes here'] < ['thermostat goes here'] and otherdevices['Hus-Varme-Hovedbryter'] == 'On' ) then
commandArray['Gang-Varmekabler']='On'
end

Hoping for some help, been googling and browsing this forum for hours.

John
Attachments
tempthermostat.JPG
tempthermostat.JPG (23.9 KiB) Viewed 1839 times
niceandeasy
Posts: 102
Joined: Thursday 28 January 2016 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: NL
Contact:

Re: noob help needed: If temperature > thermostat then

Post by niceandeasy »

Do you also have something that switches your 'Gang-Varmekabler' off?

I would use a TIME lua script for this. That runs every minute.

Code: Select all

IF ( tonumber(otherdevices_svalues['tempsensor']) < tonumber(uservariables['thermostat']) ) and otherdevices['Hus-Varme-Hovedbryter'] == 'On' then
   commandArray['Gang-Varmekabler']='On'
end
EDIT
....assuming that your thermostat value is available as a uservariable. If it is something different, replace that code or make it into a uservariable.
jhenrikb
Posts: 26
Joined: Sunday 08 January 2017 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: noob help needed: If temperature > thermostat then

Post by jhenrikb »

Thanks for the reply. I Will use the same code to turn it off just switch it to
if (temperature > thermostat) then switch off.

Currently it runs every time the sensor picks up a new value. This is often as its 0.1celcius increments.
It's an aetotec multisensor 6 with Temp and Humidity. They share the same IDX aswell, so how I'm going to get only the temp number is also a question I forgot to ask in the main post.

The thermostat is a virtual setPoint thermostat in domoticz.

edit: I edited the thermosat til "otherdevices_svalues['Gang-Varme-Termostat'] but it didnt work.

edit2: this works, but im using numbers instead of the thermostat setpoint number. So it still needs fixing.

Code: Select all

if (devicechanged['Gang-Temp-Sensor_Temperature'] < 22 ) then
   commandArray['Gang-Varmekabler']='On'

   
elseif (devicechanged['Gang-Temp-Sensor_Temperature'] > 22 ) then
   commandArray['Gang-Varmekabler']='Off'
   
end
niceandeasy
Posts: 102
Joined: Thursday 28 January 2016 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: NL
Contact:

Re: noob help needed: If temperature > thermostat then

Post by niceandeasy »

If that Gang-Varme-Termostat is a dummy setpoint termostat, this should work:

Code: Select all

if (devicechanged['Gang-Temp-Sensor_Temperature'] < tonumber(otherdevices['Gang-Varme-Termostat']) ) then
   commandArray['Gang-Varmekabler']='On'

elseif (devicechanged['Gang-Temp-Sensor_Temperature'] > tonumber(otherdevices['Gang-Varme-Termostat']) ) then
   commandArray['Gang-Varmekabler']='Off'
end
You need to use tonumber( ), because the otherdevices['setpointthermostat'] returns a string that represents a number.



For heating, I recommend an extra thermostat switch in the power line to your Varmekabler, set to 25 degrees or so, as a safety, in case something goes wrong in Domoticz or your scripts.
jhenrikb
Posts: 26
Joined: Sunday 08 January 2017 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: noob help needed: If temperature > thermostat then

Post by jhenrikb »

Hmm still won't work. Will try to add ['Setpoint_mydevice'] when I get home.


The heat switch have an inbuilt safety to turn off after 4 hours. So if by any chance some goes wrong it can only host for 4 hours at a time before getting a new signal. If domoticz is then bugged, it won't receive a new signal and the power stays off.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: noob help needed: If temperature > thermostat then

Post by simonrg »

How about:

Code: Select all

-- script_device_gangtempsensor.lua
commnadArray = {}
if devicechanged['Gang-Temp-Sensor'] then
-- debugging prints just to check we are getting the right things
   print('Current Gang Temp Sensor: '..devicechanged['Gang-Temp-Sensor_Temperature'])
   print('Current Set Point: '..otherdevices['Hus-Verme-Hovedbryter'])
   if tonumber(devicechanged['Gang-Temp-Sensor_Temperature']) < tonumber(otherdevices['Gang-Verma-Termostat'] and otherdevices['Hus-Verme-Hovedbryter'] == 'On' then
      commandArray['Gang-Varmekabler'] = 'On'
   else
      commandArray['Gang-Varmekabler'] = 'Off'
   end
end

return commandArray
end
I have not tested so there could be spelling mistrakes.

Reading the previous posts, my thoughts:
If you are using the in built editor then make sure to set this to a device script, if the script is lua file then script_device_gangtempsensor.lua.
Use tonumber to just make sure things are numbers when you do the comparison.
No need to do 2 comparisons, if it is temperature is low you want to heat, otherwise don't heat.
You could also check the status of the Gang-Varmekabler before sending it a command, so that you don't turn it on again if it is already on, on the otherhand it doesn't matter to send extra commands.

Always helpful to post full scripts including file name or setting on the internal editor so it is obvious what you are doing.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
jhenrikb
Posts: 26
Joined: Sunday 08 January 2017 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: noob help needed: If temperature > thermostat then

Post by jhenrikb »

simonrg wrote:How about:

Code: Select all

-- script_device_gangtempsensor.lua
commnadArray = {}
if devicechanged['Gang-Temp-Sensor'] then
-- debugging prints just to check we are getting the right things
   print('Current Gang Temp Sensor: '..devicechanged['Gang-Temp-Sensor_Temperature'])
   print('Current Set Point: '..otherdevices['Hus-Verme-Hovedbryter'])
   if tonumber(devicechanged['Gang-Temp-Sensor_Temperature']) < tonumber(otherdevices['Gang-Verma-Termostat'] and otherdevices['Hus-Verme-Hovedbryter'] == 'On' then
      commandArray['Gang-Varmekabler'] = 'On'
   else
      commandArray['Gang-Varmekabler'] = 'Off'
   end
end

return commandArray
end
I have not tested so there could be spelling mistrakes.

Reading the previous posts, my thoughts:
If you are using the in built editor then make sure to set this to a device script, if the script is lua file then script_device_gangtempsensor.lua.
Use tonumber to just make sure things are numbers when you do the comparison.
No need to do 2 comparisons, if it is temperature is low you want to heat, otherwise don't heat.
You could also check the status of the Gang-Varmekabler before sending it a command, so that you don't turn it on again if it is already on, on the otherhand it doesn't matter to send extra commands.

Always helpful to post full scripts including file name or setting on the internal editor so it is obvious what you are doing.

WITCHCRAFT! it worked, had to edit some typos like you said. Now I need to look into the code and figure why it works, then I perhaps i can sort my errors from my other LUA codes.

Edit:how rude of me. Thank you very much :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest