Automation is not working with temp sensor

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?

so in the States Page everything is working

so why not just used the

# Example configuration.yaml entry
climate:
  - platform: generic_thermostat
    name: Study
    heater: switch.electric_heater
    target_sensor: sensor.office_room_sensor_temperature
    hot_tolerance: 0.2
1 Like

Thanks, seems it’s good idea.
But I still can’t get why my code is not working. :frowning:

How about this?

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
1 Like

I’m assuming you wrote those using the automation UI editor since it is a device automation.

if so it should have been given a unique id so you can use the automation trace to see what is failing.

1 Like

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.

1 Like

If the temperature is already below 22, and continues to decrease, it won’t trigger the Numeric State Trigger.

Hm, interesting. Good remark. Maybe it’s my case, I’ll check.

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?

Yes. Use an automation to control the climate entity created by the Generic Thermostat integration. The automation would use a Time Trigger.

1 Like