Issues getting temperature-based automation to run

N00B here,

I am trying to fire off an automation that turns on the truck engine heater switch from 6:00 a.m. to 8:00 p.m. if the temperature is 40 or below. The automation works if run manually. The automation was done in the GUI.

I have tried it two different ways and neither seems to work. My efforts are below and any help is appreciated -

alias: New automation
description: >-
Turns on the truck engine heater switch from 6:00 a.m. to 8:00 p.m. if the
temperature is 40 or below.
trigger:

  • platform: template
    value_template: “{{ states(‘sensor.my_weather_station_temperature’) < 40 }}”
    condition:
  • condition: time
    after: “06:00:00”
    before: “20:00:00”
    weekday:
    • mon
    • tue
    • wed
    • thu
    • fri
    • sat
    • sun
      action:
  • service: switch.turn_on
    metadata: {}
    data: {}
    target:
    area_id: garage
    device_id: 0f0f739387cae829e9ecb84d3c261d56
  • service: notify.me_gmail_com
    metadata: {}
    data:
    message: The truck engine heater is on. DONT FORGET TO UNPLUG THE CORD!
    target: [email protected]
    title: F250
    mode: single

alias: Truck Engine Heater On - 6:00 a.m. to 8:00 p.m.
description: >-
Turns on the truck engine heater switch from 6:00 a.m. to 8:00 p.m. if the
temperature is 40 or below.
trigger:

  • platform: numeric_state
    entity_id:
    • sensor.my_weather_station_temperature
      attribute: current_temperature
      below: 41
      for:
      minutes: 5
  • platform: numeric_state
    entity_id:
    • sensor.my_weather_station_temperature
      for:
      hours: 0
      minutes: 5
      seconds: 0
      attribute: current_temperature
      below: 40
      above: -10
      condition:
  • condition: time
    after: “06:00:00”
    before: “20:00:00”
    weekday:
    • mon
    • tue
    • wed
    • thu
    • fri
    • sat
    • sun
      action:
  • service: switch.turn_on
    metadata: {}
    data: {}
    target:
    area_id: garage
    device_id: 0f0f739387cae829e9ecb84d3c261d56
  • service: notify.me_gmail_com
    metadata: {}
    data:
    message: The truck engine heater is on. DONT FORGET TO UNPLUG THE CORD!
    target: [email protected]
    title: F250
    mode: single

Please format your configuration properly so we can tell whether you have structural errors and so we can use copy/paste without introducing issues with quote marks.

Manually running automations skips any triggers and conditions. It is only useful for testing the actions.

Your 2 examples invoke two different pieces of data i.e. the state of the sensor and the current_temperature attribute. Which of these hold the actual value you want the automation to be based on?

Both the template and Numeric state triggers you have shown require the temperature to change from 40 or above to less than 40 degrees. If it is already under 40 at 6AM, the those triggers will not fire. What you likely want to do is to have triggers for both time and temperature, and mirror those triggers in the Condition block:

trigger:
  - platform: numeric_state
    entity_id: sensor.my_weather_station_temperature
    below: 40
    for: "00:05:00"
  - platform: time
    at: "06:00"
condition:
  - condition: numeric_state
    entity_id: sensor.my_weather_station_temperature
    below: 40
  - condition: time
    after: "06:00"
    before: "20:00"
action: ...
1 Like

My apologies and thanks for the link for proper formatting. I knew that I would get dinged for that but couldn’t figure out how to add the YAML code. Yes, I know that running an automation skips triggers and conditions just wanting to state that the end result works.

As dumb as it may sound, I am not sure which method is best. Ignorance says current_temerature should be the best route. I have added your suggestions and will see if it works in the am… I am reading all I can but if there are any resources what want to point me to I am all in.

I am a network engineer by trade and this is a humbling experience… lol