Hey guys,

I made an automation that powers off my bluetooth speaker (using IR blaster) when ChromeCast is powered off for more than 10 s. Automation is working fine, but sometimes ChromeCast changes state from OFF to Unavailable and back to OFF in just a few seconds. I have no idea why is that happening, but it triggers automation and turns ON the speaker (it is the same IR button for ON and OFF) and gets it out of sync.

What condition or trigger should I use to make it work only when ChromeCast state changes from ON to OFF and ignores Unavailable to OFF?

There is my automation:


alias: Turn off JBL
description: if CC is off for 10 sec
trigger:
  - platform: device
    type: turned_off
    device_id: bc1049ea43a53092952d364749c3fb4c
    entity_id: ae0ea35649746ed5cea16f8d6ca54dd3
    domain: remote
    for:
      hours: 0
      minutes: 0
      seconds: 10
condition: []
action:
  - service: remote.send_command
    metadata: {}
    data:
      num_repeats: 1
      delay_secs: 0.4
      hold_secs: 0
      device: jbl
      command: "off"
    target:
      device_id: 4f1f3a13324e03646ff6b03aed27f2fe
mode: single

thanks in advance

  • thegreekgeek@midwest.social
    link
    fedilink
    English
    arrow-up
    1
    ·
    6 months ago

    How I keep that sort of thing in a single automation is by using trigger IDs and a service call with a template for said trigger id.

    Something like this:

    alias: Hallway Motion Light
    description: ""
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.hallway_motion_occupancy
        to: "on"
        id: "on"
      - platform: state
        entity_id:
          - binary_sensor.hallway_motion_occupancy
        to: "off"
        id: "off"
        for:
          hours: 0
          minutes: 1
          seconds: 0
    condition: []
    action:
      - service: light.turn_{{ trigger.id }}
        data:
          transition: 3
        target:
          entity_id: light.hallway_light_2_2
    mode: single