Finally after months of just playing with many sonoff/smartlife sensors and smart lights/curtains from my app only I have created a new docker with home assistant and portainer.
Getting to grips with it.
Now one issue is I’m having is one specific automation I want to achieve.
Th16 temp probe downstairs.
I have an sonoff R3 switch triggering 3 contactors for underfloor heating.
I want an automation for the R3 to be triggered only when
(Temp >22 and <26) and time between 15:00 and 17:00)
If it rises to 26 or above then turn the R3 off. BUT also turn it back on again if the temp falls within that time frame.
I’ve only achieved it turning on and not off. I need it to be monitoring the data from the sensor.
I need a script that will read the realtime data at intervals from the TH16 and control the R3.
I suppose I could use the ‘auto’ mode on the TH16 on/off and use that as a trigger OR read the real time temps from the sensor in manual mode.
Spent hours trying to use automation.reload, automation.turnon every minute etc. automation with a script.
There must be a way to read the temps every interval and either keep the R3 turned on or off withing specified time frames.
something like my SQL knowledge
Case when Temp => 22 AND Time between 15:00 and 17:00 THEN switch.R3 ON
WHEN Temp Temp > 26 AND Time between 15:00 and 17:00 THEN switch.R3 OFF
ELSE Turn.R3 OFF END as ‘Heating Control’
In a loop reading the temperature data sent to HA. I can see it in the graphs so the TH16 is sending the data.
Post the actual entity_ids of all the things that need to be monitored and controlled. This will help us create examples that are tailored to your system.
I’ve seen people create templates and then use a trigger set at intervals with ‘/5’ for example.
Haven’t learnt about the templates yet.
Still playing around with different ideas possibly to read if the TH sonof is switched on (from the auto mode with temp range set) and then trigger the heating.
Or just to read the temperature that is stored in the HA database somehow.
Just did a test with a lamp with simple conditiions.
alias: test light interval
description: ‘’
trigger:
minutes: /1
platform: time_pattern
condition:
after: ‘13:35’
before: ‘13:53’
condition: time
action:
amended it to the heating switch. see what happens at 15:00hrs today! (MUST switch off before 17:00 as this is when out electricity tariff triples at peak time)
id: ‘1588091860855’
alias: Heating ON
description: ‘’
trigger:
So even if the temperature reaches >26 before the time threshold and switches off it will switch back on again if the temperature falls below 22? The trigger is reading the temperature data intermittently?
I thought once the trigger had run it will not run again until the beginning of the time threshold. Hence the time interval
Here’s the difference between triggers and conditions.
Trigger: You ask someone to monitor the street and report to you whenever they see a car pass by.
Condition: Examine the reported car and proceed to the Action only if it’s red and the current time is between noon and 2:00 PM.
Action: Do something.
In your case, you want Home Assistant to monitor the temperature sensor and report whenever the temperature crosses certain thresholds. Then you check if the report was made within a desired time range. If the condition is satisfied, you proceed to the Action.
NOTE
It’s possible to combine the two automations (shown above) into one automation. However, until you’re comfortable understanding how those two work, it’s best not to muddle things with a more complex, single automation.
This is great! Wasn’t able to achive any of this with the simple firmware on the TH device.
This will actually be used for a floor temp sensor.
Once the tiles start heating up I’ll want them to stay between 25-26c for example. Not the air temp.
As it takes very long the the underfloor heating to get to that temp I want to keep it withing a tight range.
So within 2 or 3 time periods in a day it will heat up to 26c say and if it drops to 24.5 or 25 then switch on again.
At least I have the basic concept sorted now thanks to your help and can just tweak it now.
One more thing, these two automations are time-constrained to operate with a period of ~2 hours. That means you have consider what could happen at the start and end of the period (notably at the end of the period).
For example, let’'s say the heat is on at 16:54 because the temperature has not yet reached 26. It reaches 26 at 16:57, triggers the second automation but the switch won’t be turned off because it’s currently later than 16:55. So the switch remains on and continues to heat the room …
Please format your code when sharing it in the community forum. You can do this one of two ways:
Select the code and click the </> icon in the editor’s menu.
OR
Type three consecutive backquotes ``` on a separate line before your code.
Type three more backquotes on a separate line after your code.
The Numeric State Trigger fires when the value crosses the threshold.
In your example, it will trigger the moment when the sensor’s temperature decreases below 23.7. If that happens outside the condition’s time range, the action will not be executed (i.e. switch is not turned on). If the temperature continues to fall below 23.7 it will no longer trigger the Numeric State Trigger because, as explained, it only happens when the value crosses the threshold.
What you’re experiencing is what I mentioned in my previous post concerning time-constrained automations:
you have to consider what could happen at the start and end of the period
I gave an example of what could happen at the end of the time period (the heating switch remains on). You’re observing what can happen at the start, namely the heating switch remains off.
Here’s one possible way to configure the Generic Thermostat for your needs.
It identifies the switch used to control the heater and the sensor that reports the temperature.
The minimum temperature that can be set is 22 and the maximum is 26.
The target temperature is set to 24.
The ambient temperature can deviate from the target temperature by as much as +/- 0.2 degrees before the heater is activated (so that’s a ‘deadband’ of 0.4 degrees).
Each time the heater is turned on, it’s for no less than 5 seconds.
All that’s left is to create two automations, one to enable the thermostat at 15:00 and the other to disable it at 16:55 (there is a way to combine them into a single automation but, for now, this is easier to understand).