Need help with Automation - only to run between certan time

Hello Members,

I have beed rtying for a few days now - i have a temperature sensor and have set up to turn on the smart switch to turn on at certain temperature and turn off at certain temperature reached. However i would like this to only work between 18:00 - 7:00 and this automation should not run outside of those times. Plese guide me. below is the YAML for it

alias: 21° below
description: “”
trigger:

  • type: temperature
    platform: device
    device_id: 40ad3c835cd4615fc04266bbd6c4978c
    entity_id: sensor.sensor_1_temperature_sensor
    domain: sensor
    below: 23
    condition: []
    action:
  • type: turn_on
    device_id: 2c5681da58d42474e8e57be22332e234
    entity_id: switch.pc191ha_socket_1
    domain: switch
    mode: single

A condition is what you’re after:

Specifically, a time condition is what you want:

1 Like

between trigger and action

  condition:
  - after: '18:00'
    before: 07:00
    condition: time

Please format your automations by putting them between 3 backticks !!!

1 Like

Thank you , I will give it a go and report back :slight_smile:

so i have done the following but for some reason this dosent trigger

alias: Master bedroom - 22° Below
description: “”
trigger:

  • type: temperature
    platform: device
    device_id: f330c8188fb458c4383859c6132f5166
    entity_id: sensor.sensor_2_temperature_sensor
    domain: sensor
    below: 22
    condition:
  • condition: time
    after: “18:00:00”
    before: “07:00:00”
    weekday:
    • sun
    • mon
    • tue
    • wed
    • thu
    • fri
    • sat
      action:
  • type: turn_on
    device_id: 345dff5df2200734279f3e793b2f4bdf
    entity_id: switch.masterbedroom_heater_socket_1
    domain: switch
    mode: single

As @francisp mentioned, please put your YAML between a pair of ```.

Has the temperature crossed from above to below 22C?

Hello, Yes the temperature did Cross above 22c. So i followed your and francis instruction and its the same - dosent kick in automatically. im doing it through the GUI at automation tab in settings - here is my yaml code. i dont know where to put the back tics - but this is what chat GPT Spat out for me and made sense based of the condition i had to add as per francis

- alias: "Master bedroom - 23° above"
  description: ""
  trigger:
    - platform: numeric_state
      entity_id: sensor.master_bedroom_sensor_temperature
      above: 23
  condition:
    - condition: time
      after: "18:00:00"
      before: "07:00:00"
      weekday:
        - sun
        - mon
        - tue
        - wed
        - thu
        - fri
        - sat
  action:
    - service: switch.turn_off
      target:
        entity_id: switch.masterbedroom_heater_socket_1
      entity_domain: switch
  mode: single
- id: '1684489896966'
- alias: "Master bedroom - 22° Below"
  description: ""
  trigger:
    - platform: numeric_state
      entity_id: sensor.master_bedroom_sensor_temperature
      below: 22
  condition:
    - condition: time
      after: "18:00:00"
      before: "07:00:00"
      weekday:
        - sun
        - mon
        - tue
        - wed
        - thu
        - fri
        - sat
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.masterbedroom_heater_socket_1
      entity_domain: switch
  mode: single

Yeah, don’t waste your time with that. Just spend some time reading to docs to understand how to do things yourself.

You have a couple weird formatting things in yours. Here’s a random automation I made up in the UI that should work just fine, just replace with your devices/settings:

description: ""
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.upstairs_average_temperature
    above: 75
condition:
  - condition: time
    after: "05:00:00"
    before: "19:00:00"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.backdoor_light