[Problem] Event with time won't trigger

Moderator: leecollings

cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

[Problem] Event with time won't trigger

Post by cantarevolare »

Hello,

I made this event to turn on the heating in a room when it is under a certain temperature and it is the night.
I think the first works (thanks to the or condition) but the second won't work and I think that when I use time condition, it doesnt' work :

Image

Could you help me, please ?

Thank you in advance.

++++++
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [Problem] Event with time won't trigger

Post by jvdz »

Both test look wrong to me, but could you start with explaining the what exactly you want to accomplish?
Just describe the logic you want between 7:00-19:00 and between 19:00-7:00 please.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

Hello,

Ok, you must be right because this morning, I got a loop :(

This is what I want to accomplish :
* I want the heating switch to be OFF (but ON IRL) when it is the night (19:00 / 07:00) AND the temperature is under 18 and, of course, the heating switch is not already on OFF ;
* I want the heating switch to be ON (but OFF IRL) when it is the day (07:00 / 19:00) OR when the temperature is above 19 and, of course, when the heating switch is not already on ON.

To sum up, I don't want the room to be cold ONLY the night and I don't want the room to be hot during the day because there is nobody in there.

Thank you in advance for you help.

++++++++++++
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [Problem] Event with time won't trigger

Post by jvdz »

OK so during the daytime it is easy as that is always Off.
During the Night time I would expect the heating to be on when below 18 and Off when above 19 to avoid a flip-flopping effect.
The way you describe it it will only switch on during that time when below 18 and never Off, or did I misinterpret that?
I prefer coding logic in LUA to get much better control but guess The Blockly the scenario could be something like:

Code: Select all

if "Radiateur chambre" = "On" and Time > 07:00 and Time < 19:00
Do Set "Radiateur chambre" = "Off"

elseif "Radiateur chambre" = "On" and Time < 07:00 and Chambre temp > 19 
Do Set "Radiateur chambre" = "Off"

elseif "Radiateur chambre" = "On" and Time > 19:00 and Chambre temp > 19 
Do Set "Radiateur chambre" = "Off"

elseif "Radiateur chambre" = "Off" and Time < 07:00 and Chambre temp < 18 
Do Set "Radiateur chambre" = "On"

elseif "Radiateur chambre" = "Off" and Time > 19:00 and Chambre temp < 18 
Do Set "Radiateur chambre" = "On"
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

You don't misinterpret at all : it will only switch on the night when it's under 18. But, if the temperature go above 19 during the night, I expect it to turn off.
I don't mind at all to begin coding in LUA. Could you guide me for the first condition and I'll try to make the rest, please ?

Thank you in advance for your help.

++++++++++++
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [Problem] Event with time won't trigger

Post by jvdz »

cantarevolare wrote: Thursday 09 November 2017 18:55 You don't misinterpret at all : it will only switch on the night when it's under 18. But, if the temperature go above 19 during the night, I expect it to turn off.
The turn Off bit wasn't in your explanation though. ;)
I think the posted Blockly should just do what you want. The reason for the 4 Elseif is the fact you need an OR relation for the time test and I am not sure how to put the test in brackets () like you would do in lua.
cantarevolare wrote: Thursday 09 November 2017 18:55 I don't mind at all to begin coding in LUA. Could you guide me for the first condition and I'll try to make the rest, please ?
This should be close but I haven't tested it on syntax errors. Put this into a TIME script and it will run one time per minute on the minute:

Code: Select all

commandArray = {}

time = os.date("*t")
-- Logic between 07:00 - 9:00
if time.hour >= 7 and time.hour <= 21 then
	if otherdevices["Radiateur chambre"] == 'On' then
		commandArray["Radiateur chambre"]="Off"
	end
else -- logic for the other timeslot
	-- get current temp and make that a number
	curtemp=tonumber(otherdevices_svalues['Chambre temp'])
	if otherdevices["Radiateur chambre"] == 'On' and curtemp > 19 then
		commandArray["Radiateur chambre"]="Off"
	elseif otherdevices["Radiateur chambre"] == 'Off' and curtemp < 18 then
		commandArray["Radiateur chambre"]="Off"
	else
	-- no action needed
	end
end

return commandArray
Ask when you need further explanation on the logic.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

Thank you very much.
I just pasted it and I'll see these next days if it match what I wanted to do.
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

Hello,

It won't work :(

No matter the temperature or the hour of the day, the event triggers and never allows me to switch the heat on :/
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [Problem] Event with time won't trigger

Post by emme »

well... there is NO instruction to turn ON" Radiateur chambre" ;)

maybe this would help:

Code: Select all

commandArray = {}

time = os.date("*t")
-- Logic between 07:00 - 9:00
if time.hour >= 7 and time.hour <= 21 then
	if otherdevices["Radiateur chambre"] == 'On' then
		commandArray["Radiateur chambre"]="Off"
	end
else -- logic for the other timeslot
	-- get current temp and make that a number
	curtemp=tonumber(otherdevices_svalues['Chambre temp'])
	if otherdevices["Radiateur chambre"] == 'On' and curtemp > 19 then
		commandArray["Radiateur chambre"]="Off"
	elseif otherdevices["Radiateur chambre"] == 'Off' and curtemp < 18 then
		commandArray["Radiateur chambre"]="On"
	else
	-- no action needed
	end
end

return commandArray
The most dangerous phrase in any language is:
"We always done this way"
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

Thank you for this quick answer.

If I saw what you changed, that's this part :

elseif otherdevices["Radiateur chambre"] == 'Off' and curtemp < 18 then
commandArray["Radiateur chambre"]="On"

But the "commandArray["Radiateur chambre"]="Off"" was good because my switch is reversed : when the switch is "Off", the head switches "On", and vice versa.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [Problem] Event with time won't trigger

Post by emme »

uh.. ok... then you have to better check all ON and OFF states in conditions and command... that's the deal ;)
The most dangerous phrase in any language is:
"We always done this way"
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

I don't understand: what are the cases that are not covered by this script, please ? There are already two majors conditions : before or after a certain hour, under or above a certain temperature.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [Problem] Event with time won't trigger

Post by emme »

lets' have a deep look to the script:

Code: Select all

if time.hour >= 7 and time.hour <= 21 then
	if otherdevices["Radiateur chambre"] == 'On' then
		commandArray["Radiateur chambre"]="Off"
	end
here your're saying: between 7.00 and 21.59 if Radiateur chambre in ON (= Off) then switch it OFF (=On)

the next portion will ONLY took place between 22.00 and 6.59

Code: Select all

	if otherdevices["Radiateur chambre"] == 'Off' and curtemp > 19 then
		commandArray["Radiateur chambre"]="On"
if temp above 19 and Radiateur chambre in ON (= Off) then switch it OFF (=On)

if NOT in this condition (but still between 22.00 and 7.00)

Code: Select all

	elseif otherdevices["Radiateur chambre"] == 'On' and curtemp < 18 then
		commandArray["Radiateur chambre"]="Off"
if temp under 18 and Radiateur chambre in ON (= Off) then switch it OFF (=On)

are these the condtitions?
The most dangerous phrase in any language is:
"We always done this way"
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

Yes, these are the conditions. (I didn't know that time.hour <= 21 equals 21.59 and not 20.59 but I will correct it)
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

Hello,

Is there a way to display the different value of variables in the log (or elsewhere), please ?

It could help me to know, every time it doesn't allow me to turn on (off) the heat, which conditions makes it happens and with which values.

Thank you in advance.
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

I found myself with print.

I don't understand something, so I repost my script :

Code: Select all

commandArray = {}

time = os.date("*t")
-- Logic between 07:00 - 9:00
if time.hour >= 7 and time.hour <= 18 then
	if otherdevices["Radiateur chambre"] == 'Off' then
		commandArray["Radiateur chambre"]="On"
		print("Condition 1")
		print(time.hour)
	end
else -- logic for the other timeslot
	-- get current temp and make that a number
	curtemp=tonumber(otherdevices_svalues['Chambre temp'])
	if otherdevices["Radiateur chambre"] == 'Off' and curtemp > 19 then
		commandArray["Radiateur chambre"]="On"
		print("Condition 2")
	elseif otherdevices["Radiateur chambre"] == 'On' and curtemp < 18 then
		commandArray["Radiateur chambre"]="Off"
		print("Condition 3")
	else
	-- no action needed
	end
end

return commandArray
This code is okay. But when I want to put "time.hour <= 12", it says this error : " 2017-12-15 18:36:36.534 Error: EventSystem: in Chauffage LUA: [string "commandArray = {}..."]:14: attempt to compare number with nil ". It is currently 18:36. If I put a number like 19, 20, 22, etc. no problem. If I put a number before, like 12, 15, 17, etc, it says this error. I don't understand why. :(

Coudl you help me, please ?

Thank you.
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

up
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [Problem] Event with time won't trigger

Post by jvdz »

What is the value of curtemp? ... the result of this line:

Code: Select all

curtemp=tonumber(otherdevices_svalues['Chambre temp'])
print("curtemp:",curtemp)
Guess you need to check the devicename when that is nil!

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
cantarevolare
Posts: 16
Joined: Wednesday 08 November 2017 19:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Problem] Event with time won't trigger

Post by cantarevolare »

It says :
2017-12-19 18:30:03.214 dzVents: curtemp:

When I look at the json of the device, I found this :

Temp : 17.1
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [Problem] Event with time won't trigger

Post by jvdz »

Have you checked the devicename whether it is the correct one and maybe you have 2 devices with the exact same name that could confuse LUA?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest