Lamp's on / Off and Automation Off / On

Hi,

When I push a button on the dashboard a want to call an automation which will turn a lamp on and directly and automation off. Pressed the same button again the lamp will go out and the automation will go on. Sometimes you like to have manualy a lamp staying on longer then via several sensor. The first part of the YAML must be a “button” Who can assist

alias: Test met lampen uit
description: ""
triggers:
  - type: turned_on
    device_id: c2b6c54567e58b891d4ad4c2632011c5
    entity_id: 043eef5e5aa194a7dbd2a12c00421868
    domain: switch
    trigger: device
    id: AutomationOff
  - type: turned_off
    device_id: c2b6c54567e58b891d4ad4c2632011c5
    entity_id: 043eef5e5aa194a7dbd2a12c00421868
    domain: switch
    trigger: device
    id: AutomationOn
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - AutomationOn
        sequence:
          - action: automation.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: automation.zijkant
          - type: turn_off
            device_id: c2b6c54567e58b891d4ad4c2632011c5
            entity_id: 043eef5e5aa194a7dbd2a12c00421868
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - AutomationOff
        sequence:
          - action: automation.turn_off
            metadata: {}
            data:
              stop_actions: true
            target:
              entity_id: automation.zijkant
          - type: turn_on
            device_id: c2b6c54567e58b891d4ad4c2632011c5
            entity_id: 043eef5e5aa194a7dbd2a12c00421868
            domain: switch
mode: single 

Why a button? Better to use a toggle. But regardless, create a button or toggle helper and add it to your dashboard, then simply use a state trigger in your automation tied to the entity_id of the button/toggle helper.

1 Like

Why are you turning automations on and off?

Enabling and disabling automations is fine if they’re seasonal - Christmas tree lights, for example - but otherwise there shouldn’t be any need if you’ve got the triggers and conditions right.

1 Like

Thanks. Can I ask you another question perhaps

This automation works fine, but stops at sunrise. But when a couple of minutes before sunrise the lamps are going on they are not going out anymore due to sunrise. Do you have a solutions?

alias: Lampen Zijkant AUTO ON / OFF 10 min. sensor VOORZIJDE 2
description: ""
triggers:
  - event_type: timer.finished
    event_data:
      entity_id: timer.lamptimer
    id: Timer Finished
    trigger: event
  - type: no_motion
    device_id: f2f17813019e8239ed99c158ef0d90f4
    entity_id: 561e1fd46fe48e16b6c2a95f3718abc8
    domain: binary_sensor
    id: Motion Stopped
    trigger: device
  - type: motion
    device_id: f2f17813019e8239ed99c158ef0d90f4
    entity_id: 561e1fd46fe48e16b6c2a95f3718abc8
    domain: binary_sensor
    id: Motion Detected
    trigger: device
conditions:
  - condition: sun
    before: sunrise
    after: sunset
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Motion Stopped
        sequence:
          - data:
              duration: "00:05:00"
            target:
              entity_id: timer.lamptimer
            action: timer.start
      - conditions:
          - condition: trigger
            id:
              - Motion Detected
        sequence:
          - data: {}
            target:
              entity_id: timer.lamptimer
            action: timer.cancel
          - type: turn_on
            device_id: c2b6c54567e58b891d4ad4c2632011c5
            entity_id: 043eef5e5aa194a7dbd2a12c00421868
            domain: switch
          - type: turn_on
            device_id: c2b6c54567e58b891d4ad4c2632011c5
            entity_id: 5206ffad2c1ed4baa5562e583b433c20
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - Timer Finished
        sequence:
          - type: turn_off
            device_id: c2b6c54567e58b891d4ad4c2632011c5
            entity_id: 043eef5e5aa194a7dbd2a12c00421868
            domain: switch
          - type: turn_off
            device_id: c2b6c54567e58b891d4ad4c2632011c5
            entity_id: 5206ffad2c1ed4baa5562e583b433c20
            domain: switch
mode: single

It would seem that your sun condition prevents the timer trigger from firing. You should be able to solve it by modifying your conditions something like this:

conditions:
  - or:
      - condition: trigger
        id: Timer Finished
      - condition: sun
        before: sunrise
        after: sunset

Thanks Mayhem