Hi friends. I’m trying to put together a script that turns on or off a stereo. I do not know how to solve if it is off turn it on and if it is on turn it off. If someone can explain to me, I appreciate it. Greetings
- type: custom:button-card
entity: media_player.bdv_n9200w
name: BDV N9200w
tap_action:
action: call-service
service: script.bdv_n9200w_computer_on_off
bdv_n9200w_on_off:
sequence:
- condition: state
entity_id: media_player.bdv_n9200w
state: "on"
script: bdv_n9200w_on
- condition: state
entity_id: media_player.bdv_n9200w
state: "off"
script: bdv_n9200w_off
It is written like this because I use a broadlink to turn the equipment on or off.
Thanks friend. I could solve it with the link you gave me.
bdv_n9200w_on_off:
sequence:
- choose:
- alias: "IF on"
conditions:
- condition: state
entity_id: media_player.bdv_n9200w
state: "playing"
sequence:
- service: script.bdv_n9200w_onoff
- alias: "IF off"
conditions:
- condition: state
entity_id: media_player.bdv_n9200w
state: "unavailable"
sequence:
- service: script.bdv_n9200w_onoff
bdv_n9200w_onoff:
sequence:
- service: remote.send_command
target:
entity_id: remote.broadlink_m3_remote_living
data:
command: b64:xxxxxxxx
123
(Taras)
November 23, 2021, 11:16pm
4
Why does the script bother to check if the media_player is playing
or unavailable
if it does the same thing (call script.bdv_n9200w_onoff
) for both of them?
If you’re interested, you can do it in one script:
bdv_n9200w_on_off:
sequence:
- choose:
- conditions: "{{ states('media_player.bdv_n9200w') in ['playing', 'unavailable'] }}"
sequence:
- service: remote.send_command
target:
entity_id: remote.broadlink_m3_remote_living
data:
command: b64:xxxxxxxx
default: []
ahhh perfect. It’s true. I understood. Thank you so much