Need Help With First Automation

Hi All!

I’m trying to change the scene for my lights depending on what time the sensor is triggered.

My background is writing websites, so I’m learning how to write automation yaml files.
The problem is that I’m trying to include if/then/else conditions. If I were writing it in a website, it would look like this.

  • alias: Kitchen Lights

    trigger:

    • type: motion
      platform: device
      device_id: 88193dc03fbfec4d70ba99174ec5393a
      entity_id: binary_sensor.kitchen_sensor_motion
      domain: binary_sensor

If time > 17:00 and time < 23:00
then
var_scene = scene.kitchen_bright
else
var_scene = scene.kitchen_dimmed
end if


action:

  • service: scene.turn_on
    target:
    entity_id: var_scene

You can use a choose block for that kind of thing.

automation:
  - alias: "Do the funky pidgeon"
    trigger:
      - type: motion
        platform: device
        device_id: 88193dc03fbfec4d70ba99174ec5393a
        entity_id: binary_sensor.kitchen_sensor_motion
        domain: binary_sensor
    action:
      - choose:
          - conditions: 
              - condition: time
                after: "17:00"
                before: "23:00"
            sequence:
              - service: scene.turn_on
                target:
                  entity_id: scene.kitchen_bright
        # ELSE 
        default:
          - service: scene.turn_on
            target:
              entity_id: scene.kitchen_dimmed
1 Like