Automation for a cold night

Hi. Im trying to set up an automation that turns on a heater overnight if the temperature is below 2°C. This sounds simple, but whilst Ive managed to get it to work if the temperature drops during the night, but not if its already below 2 when the night time starts. I’ve tried several different versions, but this is what Ive currently tried. The issue Im having is it doesnt seem to understand <2. Any suggestions?

alias: Cold night
description: “”
trigger:

  • platform: time_pattern
    minutes: /10
  • platform: state
    entity_id:
    • weather.forecast_home
      attribute: temperature
      to: <2
      condition:
  • condition: time
    after: “19:00:00”
    before: “06:00:00”
    action:
  • type: turn_on
    device_id: 224a2208130e038dddf5d06b1c34b48a
    entity_id: bbccdd09ffaa7e4a2db5fec2a4564d29
    domain: switch
  • device_id: 7391e8624a5d7b31f686a4b894dfb03f
    domain: mobile_app
    type: notify
    message: Shed Heater on
    mode: single

Welcome. Please format your code correctly: see here.

Not sure why you thought <2 would work: have you seen the documentation for the state trigger?

You want two triggers (one numeric state and one time) and two matching conditions:

alias: Cold night
trigger:
  - platform: numeric_state
    entity_id: weather.forecast_home
    attribute: temperature
    below: 2
  - platform: time
    at: "19:00:00"
condition:
  - condition: numeric_state
    entity_id: weather.forecast_home
    attribute: temperature
    below: 2
  - condition: time
    after: "19:00:00"
    before: "06:00:00"
action:
  [as per your code]

That will trigger at 19:00 and whenever the temperature drops below 2°C, but only continue to the action if its both cold and within your time window.

1 Like

Thank you, Ill try that and let you know how I get on.

Is there another automation to turn off the shed heater?

You could try the generic_thermostat integration, and then create an automation with time-based triggers to set the require setpoint on the thermostat (or even have it based on sunrise/sunset)

1 Like

Exactly how I implement space heaters around my property. I used to do automations and multiple devices and it got so complex that I instead went this route and haven’t looked back. I do the same for humidifiers too using the generic hygrostat templates.