Scene - knowing state

I have a configuration split into separate files and this is my scenes.yaml file:

  • name: Movies
    entities:
    switch.mbr_aircon: on
    switch.mbr_fan: off
    switch.mbr_light: off
    switch.mbr_tv: on
  • name: Sleep
    entities:
    switch.mbr_aircon: on
    switch.mbr_fan: off
    switch.mbr_light: off
    switch.mbr_tv: off

(sorry for the lack of formatting if messed up but the file does process correctly).

All the items are controlled by a Broadlink RM Pro with fan using 433MHz and IR for the rest.

The problem is that 3 of the 4 items - all except the fan - use the same button to turn the device on OR off.

So, if I am in Movie mode and then want to go to sleep, just the TV should turn off.
However, the aircon and light also toggle from their existing state!

HA appears to know the state of the switches so I am a bit confused as to why it would toggle them - is it because it doesn’t look at the state but if the scene says to turn the light off it will trigger the off action even if it is already off? Or do I have to add some more configuration?

1 Like

Hi there,

I have the same problem. I tried using “script” instead of “scene” but the behavior is the same…

audioscene:
    alias: Audio Scene
    sequence:
      - service: switch.turn_on
        entity_id: switch.amplifier
      - service: switch.turn_off
        entity_id: switch.projector

Would love for an expert to tell us how to not “turn off” an existing switch that is already off…

thanks

UPDATE: seems like https://home-assistant.io/getting-started/scripts-conditions/ is detailing some options, conditions may stop the script/automation. But it doesn’t help in our case, with different devices to test independently…

Yeah - you’ll need to either use automations or scripts and implement conditions. In a script, you can use conditions along the way to halt processing of any service that follows that condition. You don’t get if/else, but you can usually work something out.

Thanks but I don’t see how it would be implemented.

Example: if the A/C is on, then stop the script because we don’t want to turn it on 2 times… the script would then stop and not check for other devices.

The way I do it is have each device in a separate script with it’s own condition and then just call the scripts in a scene. I have one device in my away scene but you can more with the same state condition in their respective scripts and reference them in the scene. Example below:

script:     
  ecobee_away_mode:
    sequence:
    - condition: state
      entity_id: "input_boolean.away_mode_ecobee"
      state: "on"
    - service: climate.set_hold_mode
      data:
        entity_id: climate.ecobee
        hold_mode: 'away'


scene:
  - name: away
    entities:
      remote.bedroom: off
      remote.living_room: off
      media_player.bedroom: off
      media_player.living_room_2: off
      script.ecobee_away_mode: on
1 Like

Thanks! I’ll try that.

I still think this should be standard behavior but at least you provided me with a workaround. Thanks. Hope it will work for DPB too.

I agree - it could be helpful if you set the state of a switch to “on”, to have it know that and not resend. But there are situations where the opposite is helpful, too. So you have to put some logic into how you handle things.

I’m going to code up some changes in the command-line switches, at least for my usage for now. Could you tell me in which case you would see useful turning on a device that is already on?

If you had a switch that was turned off locally, but hadn’t been polled by HASS yet (so HASS didn’t know it’s state), you’d want an ON to dependably turn a light ON.

Interesting, I understand better the possible complications then. Thanks