Page 1 of 2

[Problem] Event with time won't trigger

Posted: Wednesday 08 November 2017 19:57
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.

++++++

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

Posted: Wednesday 08 November 2017 20:09
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

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

Posted: Thursday 09 November 2017 11:10
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.

++++++++++++

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

Posted: Thursday 09 November 2017 18:48
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

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

Posted: Thursday 09 November 2017 18:55
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.

++++++++++++

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

Posted: Thursday 09 November 2017 19:14
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

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

Posted: Friday 10 November 2017 9:26
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.

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

Posted: Thursday 14 December 2017 12:13
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 :/

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

Posted: Thursday 14 December 2017 12:32
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

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

Posted: Thursday 14 December 2017 13:59
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.

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

Posted: Thursday 14 December 2017 14:00
by emme
uh.. ok... then you have to better check all ON and OFF states in conditions and command... that's the deal ;)

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

Posted: Thursday 14 December 2017 14:29
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.

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

Posted: Thursday 14 December 2017 14:50
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?

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

Posted: Thursday 14 December 2017 15:10
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)

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

Posted: Friday 15 December 2017 8:06
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.

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

Posted: Friday 15 December 2017 18:37
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.

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

Posted: Tuesday 19 December 2017 13:25
by cantarevolare
up

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

Posted: Tuesday 19 December 2017 13:37
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

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

Posted: Tuesday 19 December 2017 18:35
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

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

Posted: Tuesday 19 December 2017 18:57
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