I have Aqara WSDCGQ11LM sensor and Xiaomi ZNCZ04LM power plug (Zigbee devices, integrated through zigbee2mqtt, and they work well directly). And I wish to create quite basic automation: turn on power plug on 22 C (value from described sensor) and turn off it on 23 C. This is related code:
alias: Electric Heater Turn On
description: Turning on electric heater if temperature is above some value
trigger:
- type: temperature
platform: device
device_id: e16c0b391176a4b93d47f1626e82531b
entity_id: sensor.office_room_sensor_temperature
domain: sensor
below: 22
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
condition: []
action:
- type: turn_on
device_id: 57afa4d7faf51d59263b251816d30c8e
entity_id: switch.electric_heater
domain: switch
mode: single
alias: Electric Heater Turn Off
description: Turning off electric heater if temperature is above some value
trigger:
- type: temperature
platform: device
device_id: e16c0b391176a4b93d47f1626e82531b
entity_id: sensor.office_room_sensor_temperature
domain: sensor
above: 23
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
condition: []
action:
- type: turn_off
device_id: 57afa4d7faf51d59263b251816d30c8e
entity_id: switch.electric_heater
domain: switch
mode: single
That’s not working for some not obvious reason for me. I mean it works but not always…what am I doing wrong?
alias: Electric Heater Turn On
description: Turning on electric heater if temperature is above some value
mode: single
trigger:
- platform: numeric_state
entity_id: sensor.office_room_sensor_temperature
below: '22'
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.electric_heater
Was the office’s temperature already below 22 when you created the automation?
If it was, the automation won’t trigger until it first rises above 22.
A Numeric State Trigger triggers when the value crosses the threshold: temperature goes from a value above 22 to a value below 22. If the temperature is already below 22, and continues to decrease, it won’t trigger the Numeric State Trigger.
Instead of using automations to control the heater, I suggest you consider using the Generic Thermostat integration. It will hold the temperature at a desired value and it can be displayed in the UI using the Thermostat card.
Thanks. That was already suggested by @myle. This feature is fantastic.
By the way, maybe you have better idea how to do next. I wish to set my electric heater (generic thermostat with it) to, let it be, 18 C for night time. How to do that correct? Is it possible to do with automation only? To set 18C at starting night and set back to normal temperature at day start?