Automation created scene not triggering

Made an automation for camera notifications from frigate dependent on what it sees but the created scene for the lights doesn’t trigger to restore them back to their previous state anymore:

alias: Notification AV (Gate)
description: ""
trigger:
  - platform: mqtt
    topic: frigate/events
    payload: GateCam1
    value_template: "{{ value_json[\"after\"][\"camera\"] }}"
    variables:
      after_zones: "{{ trigger.payload_json[\"after\"][\"entered_zones\"] }}"
      before_zones: "{{ trigger.payload_json[\"before\"][\"entered_zones\"] }}"
      camera: "{{ trigger.payload_json[\"after\"][\"camera\"] }}"
      id: "{{ trigger.payload_json[\"after\"][\"id\"] }}"
      label: "{{ trigger.payload_json[\"after\"][\"label\"] }}"
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: person.me
        state: home
      - condition: state
        entity_id: input_boolean.guest_mode
        state: "on"
  - condition: or
    conditions:
      - condition: template
        value_template: "{{ trigger.payload_json['type'] == 'new' }}"
      - condition: template
        value_template: "{{ trigger.payload_json['type'] == 'update' }}"
        enabled: false
      - condition: template
        value_template: "{{ before_zones | length == 0 }}"
  - condition: template
    value_template: "{{ trigger.payload_json[\"after\"][\"entered_zones\"]|length > 0 }}"
  - condition: template
    value_template: >-
      {{ ["Driveway1"]|select("in",
      trigger.payload_json["after"]["entered_zones"])|list|length > 0 }}
  - condition: time
    after: "07:00:00"
    before: "20:00:00"
    enabled: true
action:
  - parallel:
      - if:
          - condition: state
            entity_id: media_player.nad_amp_sir
            state: "off"
        then:
          - service: media_player.turn_on
            data: {}
            target:
              entity_id: media_player.nad_amp_sir
        enabled: true
      - if:
          - condition: state
            entity_id: media_player.cyrud_preamp_sir
            state: "off"
        then:
          - service: media_player.turn_on
            data: {}
            target:
              entity_id: media_player.cyrud_preamp_sir
      - parallel:
          - if:
              - condition: state
                entity_id: media_player.chromecastaudiohgarden
                state: "off"
            then:
              - service: media_player.turn_on
                data: {}
                target:
                  entity_id: media_player.chromecastaudiohgarden
          - service: media_player.volume_set
            data:
              volume_level: 0.2
            target:
              entity_id: media_player.chromecastaudiohgarden
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: tts.google_translate_say
            data_template:
              entity_id: media_player.chromecastaudiohgarden
              message: There is a {{label}} at the gate
  - parallel:
      - service: scene.create
        data:
          scene_id: notificationwled
          snapshot_entities:
            - light.wled_kitchen_counter_master
            - light.dining_table_panel
            - select.wled_kitchen_counter_preset
            - select.dining_table_panel_preset
            - select.wled_kitchen_counter_color_palette
            - select.dining_table_panel_color_palette
        enabled: true
      - service: scene.create
        data:
          scene_id: gatenotificationlight
          snapshot_entities:
            - light.main_hall_lamp
            - light.led_controller_4_cct
            - light.led_controller_4_rgb
        enabled: true
      - service: scene.create
        data:
          scene_id: gatenotificationlight
          snapshot_entities:
            - light.main_hall_lamp
            - light.led_controller_4_cct
            - light.led_controller_4_rgb
            - light.wled_kitchen_counter_master
            - light.dining_table_panel
            - select.wled_kitchen_counter_color_palette
            - select.dining_table_panel_color_palette
        enabled: false
      - service: light.turn_on
        data:
          rgb_color:
            - 0
            - 255
            - 0
          brightness_pct: 100
          flash: long
        target:
          entity_id:
            - light.main_hall_lamp
        enabled: true
      - service: select.select_option
        data:
          option: Indicator2
        target:
          entity_id:
            - select.wled_kitchen_counter_preset
            - select.dining_table_panel_preset
      - delay:
          hours: 0
          minutes: 0
          seconds: 7
          milliseconds: 0
      - service: scene.turn_on
        target:
          entity_id: scene.gatenotificationlight
        metadata: {}
      - service: scene.turn_on
        target:
          entity_id: scene.notificationwled
        metadata: {}
        enabled: true
    enabled: true
  - if:
      - condition: state
        entity_id: media_player.kitchen_cast
        state: unavailable
    then:
      - parallel:
          - service: media_player.turn_on
            data: {}
            target:
              entity_id: media_player.kitchen_tv
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - media_player.kitchen_cast
                to: "off"
            continue_on_timeout: false
          - service: media_player.play_media
            target:
              entity_id: media_player.kitchen_cast
            data:
              media_content_id: media-source://camera/camera.gatecam1
              media_content_type: image/jpeg
            metadata:
              title: null
              thumbnail: /api/camera_proxy/camera.gatecam1
              media_class: video
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://camera
    else:
      - condition: state
        entity_id: media_player.kitchen_cast
        state: playing
      - stop: ""
  - if:
      - condition: state
        entity_id: media_player.main_hall_tv
        state: "on"
      - condition: not
        conditions:
          - condition: state
            entity_id: media_player.playstation_4
            state: playing
          - condition: state
            entity_id: media_player.playstation_4
            state: paused
          - condition: state
            entity_id: media_player.playstation_4
            state: idle
    then:
      - parallel:
          - service: androidtv.adb_command
            data:
              command: >-
                ps -ef | grep -v grep | grep pipup || am start
                nl.rogro82.pipup/.MainActivity
            target:
              entity_id: media_player.android_tv_192_168_1_216
          - service: androidtv.adb_command
            data:
              command: input keyevent KEYCODE_WAKEUP
            target:
              entity_id: media_player.android_tv_192_168_1_216
          - service: rest_command.pipup
            data:
              title: Gate camera
              message: There is a {{ label }} at the gate
              width: 480
              height: 340
              url: http://192.168.1.108:5000/api/GateCam1
    enabled: true
mode: single

Problem is scene.gatenotificationlight in the 2nd parallel action. Sidenote:I bracketed my scenes because the WLED presets sometimes turn the lights back on when I don’t need them to and having them all together didn’t work before.

- parallel:
      - service: scene.create
        data:
          scene_id: notificationwled
          snapshot_entities:
            - light.wled_kitchen_counter_master
            - light.dining_table_panel
            - select.wled_kitchen_counter_preset
            - select.dining_table_panel_preset
            - select.wled_kitchen_counter_color_palette
            - select.dining_table_panel_color_palette
        enabled: true
      - service: scene.create
        data:
          scene_id: gatenotificationlight
          snapshot_entities:
            - light.main_hall_lamp
            - light.led_controller_4_cct
            - light.led_controller_4_rgb
        enabled: true
      - service: scene.create
        data:
          scene_id: gatenotificationlight
          snapshot_entities:
            - light.main_hall_lamp
            - light.led_controller_4_cct
            - light.led_controller_4_rgb
            - light.wled_kitchen_counter_master
            - light.dining_table_panel
            - select.wled_kitchen_counter_color_palette
            - select.dining_table_panel_color_palette
        enabled: false
      - service: light.turn_on
        data:
          rgb_color:
            - 0
            - 255
            - 0
          brightness_pct: 100
          flash: long
        target:
          entity_id:
            - light.main_hall_lamp
        enabled: true
      - service: select.select_option
        data:
          option: Indicator2
        target:
          entity_id:
            - select.wled_kitchen_counter_preset
            - select.dining_table_panel_preset
      - delay:
          hours: 0
          minutes: 0
          seconds: 7
          milliseconds: 0
      - service: scene.turn_on
        target:
          entity_id: scene.gatenotificationlight
        metadata: {}
      - service: scene.turn_on
        target:
          entity_id: scene.notificationwled
        metadata: {}
        enabled: true
    enabled: true

Are you sure all those parallel actions are what you really want to do? It looks like you’re trying to define the same scene two different ways at the same time while you are also turning it on, altering the state of one of it’s entities, delaying, and doing a bunch of other stuff…

Yeaaahhhh. I had a sleep on it & seen my mistake. Can I split the automation up: trigger & conditions in one, different ranges of actions in another automation that gets triggered by the former?

Yes, the basic method is usually to break your action groups out into individual scripts and have your automation handle the triggers, general conditions, and selection logic; but there are many ways to split or combine automations. If you want to structure it as one automation triggering other automations you will likely want to use custom events.

Make sure to check out:
Calling scripts: waiting vs non-waiting
Raise and Consume Events

1 Like