Multiple triggers and Lua code problems

I’m trying to create some simple scene, triggered by temperature sensor from Netatmo station, but run only during certain time of day (like: if temperature drops below 0 degrees, then turn on electric heater, but only between 10:00 and 13:00. (another topic is that heater should be turned on also if at 10:00 temperature is already below 0 degrees)

I created a scene triggered by chosen temperature sensor from Netatmo. Then I added a code which I’ve found on this forum, modifying it to desired hours:

local pStart = “22:30” – Start of time period
local pEnd = “06:15” – End of time period
local allow = true – true runs scene during period, false blocks it
local hS, mS = string.match(pStart,“(%d+)%:(%d+)”)
local mStart = (hS * 60) + mS
local hE, mE = string.match(pEnd,“(%d+)%:(%d+)”)
local mEnd = (hE * 60) + mE
local tNow = os.date(“*t”)
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

The scene turns on smartplug with a heater attached to it.
So far it was good, when real temperature was below desired one the scene was triggered but only within desired timeframe.
But then I changed temp. condition to be below real reading (should give me false as a result and scene shouldn’t run) and… the plug was still turning on.

After several tries, since I have only few items attached to the central unit I decided to make reset of the central unit, re-installing all devices and setting the scenes again from scratch.|
And now… srurprise - after enering the same code which was working before, I am getting an error “Error in Lua for scenes and events”.
I don’t understand it, what I am doing wrong?

How to set this scene to be properly working?

Another topic is a functionality which is implemented in current release of UI7 - setting a trigger I can restrict it to certain times and weekdays. How does it work? This is the AND or OR condition?
I tried to set this up, but also with poor results. I am not really sure if the time restriction is really working (seem to have no matter for the rule to be triggered)

I’ve searched through the forum but also with no success. I am quite lame in coding and totally newbie to Vera, so it may be that I don’t know the proper keywords :frowning:
May I ask you for some kind of step by step walktrough to understand how to work it out properly?

OK, so I will answer myself.

According to the first topic (not working lua code) I’ve got an answer from Customer Support that current release have some issues with code using special symbols (like “%”) and this cause the problem.

According to the second topic the restriction is AND type (the trigger parameter AND within desired time). It works regardless if the condition for the trigger was reached before or during defined period of time.
BUT there is something interesting - the threshold for meeting a specified condition is different for “go below” and “go above” defined target. For temperature reading the “go below” condition seems to have threshold of 0.1 degree (so if the condition is i.e 20 degrees, the scene will be triggered when temperature gets 19.9), while the “go above” seems to have threshold of 1 degree (so if the condition is 20 degrees, the scene will not be triggered until reaching 21.1).

Maybe above will be helpful for somebody.