Automation Stops Working Each Day Unless Toggled

I have an automation setup to control a small oil-filled radiator near my desk. What I want to happen is that during working days and during working time, I want to check a temperature sensor and use that to control the state of the heater via a smart plug. The temperature sensor I have is a d1 mini using esphome and operates as I’d expect it to without issue. It has not yet stopped reporting temperature changes over this entire period of using these automations. The plug is a topgreener plug flashed with Tasmota. It works on its own without issue.

The automations were setup via the UI, then I shared them here by copying them from the Edit as YAML mode.

The automation worked as expected the first day I set it up. The next day the heater wasn’t on, so I tried changing the restart settings, saved it, and it worked again. I thought it might be fixed, but the next day it wasn’t working again. This time, I just toggled the automations off then back on and it worked again. Today is the 3rd work day where this same thing has happened. It doesn’t work until I toggle the automation off, then back on.

I’m having trouble understanding what about this automation is failing after working for a day. I have tried changing the restart modes to queue, but it did not help.

Automation 1: Turn the Plug on
This looks for a change in state on the sensor and turns the plug on, but only during the work days/times.

alias: Office Heater Control (On)
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.office_temperature
    below: '70'
condition:
  - condition: time
    after: '07:00:00'
    before: '16:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - type: turn_on
    device_id: f92ce5f7caa27aa2f55f2e24383348b0
    entity_id: switch.office_heater_plug
    domain: switch
mode: queued      # I've tried all the different modes here without success
max: 10

Automation 2: Turn the Plug Off
Here, I’m looking for the room to either be too warm or for the work day to be over. For either condition, turn the plug off

alias: Office Heater Control (Off)
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.office_temperature
    above: '71'
  - platform: time
    at: '17:00:00'
condition: []
action:
  - type: turn_off
    device_id: f92ce5f7caa27aa2f55f2e24383348b0
    entity_id: switch.office_heater_plug
    domain: switch
mode: queued
max: 10

I see Taras is responding, so I’ll give up now, just say “I was out Ninja’d”

1 Like

What you are experiencing is expected because of how a Numeric State Trigger works.

The trigger occurs at the moment when the temperature decreases below the threshold value of 70. After it has crossed the threshold, the trigger is “set” and will not re-trigger if the temperature continues to decrease.

To reset the Numeric State Trigger, the temperature must rise above the threshold. When it decreases below the threshold, it will trigger again. Another way to reset the Numeric State Trigger is to execute Reload Automations or restart Home Assistant (and, although I haven’t checked, possibly when turning the automation off/on).

Your automation has a Time Condition which exacerbates the behavior I just described. If the temperature falls below 70 outside the time range, the automation will not turn on the heater. However, now that the Numeric State Trigger is “set”, even when the time falls within the range, it won’t trigger. The temperature continues to fall yet the heater is never turned on.


You’re not the first person who has attempted to use a Numeric State Trigger to control a heater’s operation (and encountered the same problem). What I have suggested to people facing this situation is to use the Generic Thermostat integration to manage the temperature. Your automation would simply enable/disable the Generic Thermostat at the desired times. The bonus is that you get a nice Thermostat Card to control the temperature.

Let me know if this approach interests you and I can help you configure it.

1 Like

Ok thanks a bunch, that seems obvious now, but for some reason I wasn’t getting it from the documentation even though on second look it would suggest that behavior. I was thinking for some reason the way i had it setup it would trigger that event any time the temperature is updated and it is below the threshold I configured. But, I suppose that kind of approach would be inefficient.

I’ll definitely take a look at the generic thermostat option. I wasn’t aware that it existed and it appears to be what I wanted anyways.

I’d do exactly as Taras suggests
And I’d have a sensor (template) to set the temperature to (say) 70 when Mon-Fri between times Or to (say) 0 for all other times OR if a ‘holiday_binary’ was set

This will take care of the time constraints and overide at the time limits

I also suggest you look at the keep_alive: option

This should help you get started with what I proposed:

Configuration for the climate entity using Generic Thermostat:

climate:
  - platform: generic_thermostat
    name: Office
    heater: switch.office_heater_plug
    target_sensor: sensor.office_temperature
    min_temp: 65
    max_temp: 74
    target_temp: 71
    min_cycle_duration:
      seconds: 15
    initial_hvac_mode: "heat"
    away_temp: 66

Basic automation to turn on climate.office at 07:00:00 and off at 17:00:00.

alias: Office Heater Schedule
trigger:
  - platform: time
    at:
    - '07:00:00'
    - '17:00:00'
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - service: "climate.turn_{{ 'on' if now().hour == 7 else 'off' }}"
    entity_id: climate.office
1 Like

Thanks so much for the help. This definitely got me started and is a better solution than what i was trying.

So, if I understand correctly, the keep_alive option would keep setting the expected state of the switch I have that turns the heater on/off on that interval I configure. That makes sense, but that makes me realize I’m not sure exactly what would happen without that set.

Without it, I’m guessing I could manually change the state of the plug and it is only going to be switched back when the state of the thermostat changes?

e.g., Let’s say the sun is heating the room quickly during the afternoon and the temperature reaches 75 (given the suggested climate config), so the climate device turns off the switch. Now, if I go and manually turn the switch back on, the heater is starting to heat up the 75 degree room. With keep_alive set to some interval, it would turn it back off after the interval duration. Without a keep_alive, I’m guessing it would keep heating until something triggers a state change for the climate device (beyond just temperature changes)?

Exactly.

Also, if your switch misses a command, then it will be resent according to the period you set. So every 5, 10, 15 minutes or whatever you think appropriate.
It basically repeats the ‘required’ output on the period you set

I have a z-wave boiler switch and (as far as I’m aware) the switch has ‘stuck on’ twice. I’ve since instituted the keep alive and set an additional sensor and notification to track it.
I realise this is belt, braces and a bit of string. But I’ll only run this way to prove it one way or the other.
My boiler is on the furthest edge of my z-wave
:man_shrugging: