[Problem] Event with time won't trigger

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

[Problem] Event with time won't trigger

Post by cantarevolare » Wednesday 08 November 2017 20:57

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: 1160
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Wednesday 08 November 2017 21:09

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

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

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

Post by cantarevolare » Thursday 09 November 2017 12:10

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: 1160
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Thursday 09 November 2017 19:48

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

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

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

Post by cantarevolare » Thursday 09 November 2017 19: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.
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: 1160
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Thursday 09 November 2017 20:14

cantarevolare wrote:
Thursday 09 November 2017 19: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 19: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

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

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

Post by cantarevolare » Friday 10 November 2017 10:26

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 20:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by cantarevolare » Thursday 14 December 2017 13:13

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: 699
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post by emme » Thursday 14 December 2017 13:32

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
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

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

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

Post by cantarevolare » Thursday 14 December 2017 14:59

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: 699
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post by emme » Thursday 14 December 2017 15:00

uh.. ok... then you have to better check all ON and OFF states in conditions and command... that's the deal ;)
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

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

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

Post by cantarevolare » Thursday 14 December 2017 15:29

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: 699
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post by emme » Thursday 14 December 2017 15:50

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?
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

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

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

Post by cantarevolare » Thursday 14 December 2017 16:10

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 20:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by cantarevolare » Friday 15 December 2017 9:06

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 20:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by cantarevolare » Friday 15 December 2017 19:37

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 20:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by cantarevolare » Tuesday 19 December 2017 14:25

up

User avatar
jvdz
Posts: 1160
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Tuesday 19 December 2017 14:37

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

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

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

Post by cantarevolare » Tuesday 19 December 2017 19:35

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: 1160
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » Tuesday 19 December 2017 19:57

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests