Scene always runs entity's 'turn_on' command, even if already turned on

Hi all,

Recently I’ve been busy setting up scenes in my Home Assistant and I came across the following situation:

I’ve got an older Samsung Smart TV that doesn’t support Wake On LAN, but once it is connected I can use the Samsung integration functions to turn it off. I wanted to couple the TV’s functionality with my Chromecast, so I’ve made the following universal media player:

- platform: universal
  name: Samsung tv
  children:
    - media_player.chromecast
    - media_player.samsung_ue40es5500
  commands:
    turn_on:
      service: script.samsungtv_power
    turn_off:
      service: media_player.turn_off
      entity_id: media_player.samsung_ue40es5500
    volume_up:
      service: media_player.volume_up
      entity_id: media_player.samsung_ue40es5500
    volume_down: 
      service: media_player.volume_down
      entity_id: media_player.samsung_ue40es5500
    volume_mute:
      service: media_player.volume_mute
      entity_id: media_player.samsung_ue40es5500
  attributes:
    state: media_player.samsung_ue40es5500

The script.samsungtv_power is a script that sends an IR power command, which toggles the power.

My TV scene has the following form:

- id: '1586456650331'
  name: TV
  entities:
    light.couch:
      brightness: 150
      color_temp: 420
      state: 'on'
    light.couch_small:
      state: 'off'
    [...]
    media_player.samsung_tv:
      state: 'on'

When I turn on this scene while the TV is already on, it will turn off the TV. This while Home Assistant already knows the TV is turned on.

Am I overseeing something here, or could this be a bug?

Thanks!

Have you made any progress on this?

If not, what entity can be used to determine if the TV is on or not? Also, can you post script.samsungtv_power?

Hi Phil,

Thanks for your reply.

I haven’t made any progress in the meantime. To answer your questions:

  • The entity media_player.samsung_ue40es5500 shows the actual power state (On/Off) of the TV.
  • The entity media_player.chromecast is attached to the TV via USB (TV supplies the power), so media_player.chromecast will show the same state as media_player.samsung_ue40es5500, be it with some delay.
  • The entity media_player.samsung_tv combines the states of the two entities above, but will use the power state of media_player.chromecast since this entity is the first in the ‘children’ lised in the entity definition of media_player.samsung_tv. I’ve ordered the children this way because this allows me to use the chromecast play/next commands in the combined entity.

The script.samsungtv_power contains:

samsungtv_power:
  sequence:
  - service: broadlink.send
    data:
      host: !secret broadlink_ip
      packet:
      - JgBGAJOTEjcSNxI3EhISEhISEhISEhI3EjcSNxISEhISEhISEhISEhI3EhISEhISEhISEhISEjcSEhI3EjcSNxI3EjcSNxIABfgNBQ==

I hope this clarifies your questions! Do you have any suggestions where to go from here?

Thanks, and yes. Try this:

samsungtv_power:
  sequence:
  - condition: state
    entity_id: media_player.samsung_ue40es5500
    state: 'off'
  - service: broadlink.send
    data:
      host: !secret broadlink_ip
      packet:
      - JgBGAJOTEjcSNxI3EhISEhISEhISEhI3EjcSNxISEhISEhISEhISEhI3EhISEhISEhISEhISEjcSEhI3EjcSNxI3EjcSNxIABfgNBQ==

The condition step will abort the script unless media_player.samsung_ue40es5500 is off. (That is to say, it will continue on to the next step – sending the command to toggle power – only if media_player.samsung_ue40es5500 is currently off.)

1 Like

Ah, didn’t think of it this way. Clever solution!
Thanks, I’ll implement this.

On the source of the issue; do you think it might be a bug that I should report, or is it just the way scenes work?
I mean: if the current state is already the desired scene state, no action should by taken by the system right?

It’s not a bug. If you call a service, it is run, period. It’s up to the service “handler” to decide what it should do and how to take the current state into account, if at all. In this case, by calling the turn on service with your universal media player, you’re asking it to run the service under turn_on. Since that is invoking your script, it’s up to your script to decide.

Ok, thanks for the explanation and solution!

1 Like