Hello everyone,
I just installed HAOS on Raspberry pi 4, with Sonoff Zigbee Gateway Dongle-usb.
I would like to use the following items:
Xiaomi Aqara temperature sensor
Ikea TRÅDFRI switch (to turn on/off the electric radiator).
The automations should be two:
to turn on the switch if the temperature goes below 19 degrees.
to turn off the switch if the temperature goes above 22 degrees.
I tried configuring in YAML but it doesn’t seem to work… what am I doing wrong?
alias: Soggiorno off > 22°
description: ""
trigger:
- platform: state
entity_id:
- sensor.lumi_lumi_weather_temperature
- platform: time
at: "05:30:00"
- platform: homeassistant
event: start
condition:
- condition: state
entity_id: switch.soggiorno_control_ikea_switch
state: "on"
- condition: time
after: "05:30:00"
before: "23:30:00"
- condition: numeric_state
entity_id: sensor.lumi_lumi_weather_temperature
above: "22"
action:
- type: turn_off
device_id: 1d2a2f43f866efd40cf462d8ff29c860
entity_id: switch.soggiorno_control_ikea_switch
domain: switch
mode: single
I can see several potential problems with your automation:
The state trigger is for binary entities with an on/off state, you probably need two numeric_state triggers for “below 19” and “above 22” with trigger_ids defined.
I would remove all the conditions.
For the actions I would use a choose then use the relevant trigger_id to either turn the switch on or off.
Making automations will just mean you will find more and more issues.
Such as home assistant start event (as you already pointed out in first post), but then there is the reload of automations, and if you then want to add a window contact to this it becomes even messier.
When you have a generic thermostat, you can just turn it on or off when a contact sensor says a window is open and when it closes again the thermostat will resume with what it had. Using a numeric trigger will not trigger again if the temperature is out of range already.
But this is not really correct. State is for states. It can be numeric, binary or text. Doesn’t matter.
I do understand your point about the Generic Thermostat however this would not address the timing requirements so an automation would still be requited for that.
The documentation does not appear to show that the state trigger should be used with numeric values:
There are other ways of doing this but using a choose makes it clear what is happening.
If you want to do this another way then that is fine, however your automation currently only has a turn_off action and no way of turning the switch on.
The first example in your link shows a text based state trigger.
automation:
trigger:
- platform: state
entity_id:
- device_tracker.paulus
- device_tracker.anne_therese
# Optional
from: "not_home"
# Optional
to: "home"
# If given, will trigger when the condition has been true for X time; you can also use days and milliseconds.
for:
hours: 0
minutes: 1
seconds: 0
I would say the way the automation is configured in the first post is perfectly fine.
Trigger on state change (any change) then set a condition with the upper or lower thresholds.
There is nothing wrong with that in my opinion, but it’s a generic thermostat so it’s not needed and prone to not function due to how HA reloads automations and restarts and all that.
The generic thermostat does not have those limitations as far as I know, and based on what I can see at home.
I still believe you will get a much better experience from a thermostat
Yes, I think the generic thermostat kind of does it except that from the original code that was posted it looks like the switch is only supposed to operate between 05:30 and 23:30 i.e. if the temperature drops below 19C outside of these hours then the switch should not turn on.
To achieve this an automation would be required to change the climate entities operation between off and heat.
It seems to be right the code, but in reality temperature now more than 22° (we’re lucky with lot of sun) and ikea swittch is on. I don’t understand why…
About Hellis81 suggestion with Climate I also want that during night, from 23.30 to 05.30 automation is OFF and also electric radiator. And, as a newbie, I also don’t know where to copy that code…