Hi all. I’m still lost on this topic.
I am trying to make it change the value of an input_select when someone changes the team value with a remote.
It’s possible?
- alias: bdv_n9200w_input_select
action:
- service: media_player.select_source
data:
entity_id: input_select.home
source: >
{{ state_attr('media_player.bdv_n9200w', 'media_title') }}
1 Like
jazzyisj
(Jason)
December 21, 2021, 12:55am
2
You are mixing up the media player source and an input select. The entity id for media_player.select_source must be a media player.
To change an input_select option, you must use the input_select.select_option service .
1 Like
It’s true I’m already mixing everything. I tried many things but I already lost myself.
This is the most logical thing I wrote but it doesn’t work either
- alias: bdv_n9200w_input_select
service: input_select.select_option
data_template:
option: "{{ state_attr('media_player.bdv_n9200w','media_title') }}"
target:
entity_id: input_select.home
What errors are you getting?
What you have posted is not an automation… you must have a trigger.
- alias: bdv_n9200w_input_select
description: "Set input select to value of media title whenever media title changes"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
condition: []
action:
- service: input_select.select_option
data:
option: "{{ state_attr('media_player.bdv_n9200w','media_title') }}"
target:
entity_id: input_select.home
Thank you very much friend. It is still difficult for me to find which are the triggers and for each case how to use them. It worked very well. Thanks a lot
1 Like
Hello again. In this example you can capture the new state of media_title. Can you find out what the value of media_title is before it changes? I want to know how many times I have to run a broadlink command for it to change on tv. Thanks
Could you thus save the value in a variable for later comparing it?
action:
- service: input_text.set_value
data_template:
entity_id: input_text.BDVn9200w_source_stored
value: "{{ states('sensor.BDVn9200w_source_stored') | string }}"
If this were the case, how do I make it so that if the variable contains HDM 1 and I change it to HDMI 4, run a script 3 times?
This is the closest thing to what I intend.
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
condition: >
{{
{%- sources = ["Bluetooth","Audio","DB DVD","USB","FM Present","HDMI 1","HDMI 2","TV","SCR M"] %}
{%- old_pos = sources.indexOf(input_text.BDVn9200w_source_stored) %}
{%- new_por = sources.indexOf(state_attr('media_player.bdv_n9200w','media_title')) %}
{%- if(new_pos > old_pos) {
repeat = (new_pos - old_pos);
} else {
repeat = (length(sources) - old_pos) + new_pos
}
%}
action:
- service: script.samsung_tv_source
repeat: variable repeat
You should be able to do something like:
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
condition:
- condition: template
value_template: {{ trigger.to_state.state != trigger.from_state.state }}
action:
- service: script.samsung_tv_source
data:
repeat: {{ repeats }}
variables:
repeats: >
{% set sources = ["Bluetooth","Audio","DB DVD","USB","FM Present","HDMI 1","HDMI 2","TV","SCR M"] %}
{%- set old_pos = sources.index(trigger.from_state.state) | int(0) %}
{%- set new_pos = sources.index(trigger.to_state.state) | int(0) %}
{%- if new_pos > old_pos %}
{{ new_pos - old_pos }}
{% else %}
{{ (sources|length - old_pos) + new_pos }}
{% endif %}
Excellent friend. These things that I did not know, I could do it this way.
Thank you very much for the help you always give in the forum.
condition:
- condition: template
value_template: {{ trigger.to_state.state != trigger.from_state.state }}
repeat: {{ repeats }}
variables:
repeats: >
Hello. I am having problems with the template. And I can’t find why?
invalid key: "OrderedDict([('trigger.to_state.state != trigger.from_state.state', None)])" in "/config/include/automation.yaml", line 35, column 0
12:23:44 – (ERROR) Automatización
invalid key: "OrderedDict([('trigger.to_state.state != trigger.from_state.state', None)])" in "/config/include/automation.yaml", line 35, column 0
12:23:44 – (ERROR) util/yaml/loader.py
It occurred to me that it could also be done that way. In both cases it gives me the same error
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
action:
- repeat:
sequence:
- service: script.bdv_n9200w_source
until:
- condition: template
value_template: {{ trigger.to_state.state != trigger.from_state.state }}
Mala mia… I forgot that the trigger is an attribute, so we need to modify the trigger variable templates:
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
condition: []
action:
- service: script.samsung_tv_source
repeat: "{{ repeats }}"
variables:
repeats: >
{% set sources = ["Bluetooth","Audio","DB DVD","USB","FM Present","HDMI 1","HDMI 2","TV","SCR M"] %}
{%- set old_pos = sources.index(trigger.from_state.attributes.media_title) | int(0) %}
{%- set new_pos = sources.index(trigger.to_state.attributes.media_title) | int(0) %}
{%- if new_pos > old_pos %}
{{ new_pos - old_pos }}
{% else %}
{{ (sources|length - old_pos) + new_pos }}
{% endif %
You speak Spanish lol. According to what you show me and according to the user manual I would think it is fine but it is not working.
It shows me the same error
Show us the script/automation that is causing the error.
In this earlier automation, your template will kill the repeat immediately.
The error is in the template line.
I try it with another script and it tells me the same error.
invalid key: "OrderedDict([('trigger.to_state.attributes.media_title != trigger.from_state.attributes.media_title', None)])" in "/config/include/automation.yaml", line 21, column 0
Post the whole automation.
You can’t use trigger variables in a script, because they do not have triggers.
If I set it up like this now the error is in the line {{repeat}}
condition:
- condition: template
value_template: >
{{ trigger.to_state.attributes.media_title != trigger.from_state.attributes.media_title }}
action:
- service: script.samsung_tv_source
repeat: {{ repeats }}
Automation compete
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
condition:
- condition: template
value_template: >
{{ trigger.to_state.attributes.media_title != trigger.from_state.attributes.media_title }}
action:
- service: script.bdv_n9200w_source
repeat: {{ repeats }}
variables:
repeats: >
{% set sources = ["Bluetooth","Audio","DB DVD","USB","FM Present","HDMI 1","HDMI 2","TV","SCR M"] %}
{%- set old_pos = sources.index(trigger.from_state.attributes.media_title) | int(0) %}
{%- set new_pos = sources.index(trigger.to_state.attributes.media_title) | int(0) %}
{%- if new_pos > old_pos %}
{{ new_pos - old_pos }}
{% else %}
{{ (sources|length - old_pos) + new_pos }}
{% endif %
Script complete
bdv_n9200w_source:
sequence:
- service: remote.send_command
target:
entity_id: remote.broadlink_m3_remote_living
data:
command: b64:JgDuAFESKRIVExQTKBMUEygTKBMUExUSFRIVEygSFRMoEygAApxREygSFRMTFCgTFBMnFCgTExQUExQTFBQnExQUJxQnAAKdUBQnExQUExQnFBMUJxQnFBQTFBMUExQUJxQTFCcUJwACpk8UJxQUExQTKBMUEygTKBMUExQUExQTFCcUFBMoEygAAqVQEygTFBMUFCcUExQnFCcUExQUExQTFBMoExQUJxQnAAKlUBQnFBMUExQnFBQTKBMoExQTFBMUFBMUJxQTFCcUJwACpk8UKBMUExQTKBMUFCcUJxMUFBMUFBMUEygTFBMoEygADQUAAAAAAAAAAAAA
I just tried this and it doesn’t turn on the light when I change the suorce
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
condition:
- condition: template
value_template: >
{{ trigger.to_state.attributes.media_title != trigger.from_state.attributes.media_title }}
action:
- service: switch.turn_on
entity_id: switch.cuarto_mile
I realized that this is a mistake. Because it does not change the media_player but the input_select
trigger:
- platform: state
entity_id: media_player.bdv_n9200w
attribute: media_title
This doesn’t work either
- alias: bdv_n9200w_change_source
description: "Cambia input_select cuando se cambia desde home assistant"
trigger:
- platform: state
entity_id: input_select.home
action:
- service: switch.toggle
entity_id: switch.cuarto_mile
I’m now a little confused as to what the goal is…
Tells me:
Error loading /config/configuration.yaml: invalid key: "OrderedDict([('repeats', None)])"
in "/config/include/automation.yaml", line 244, column 0
in this line:
count: {{ repeats }}
in the script
Error loading /config/configuration.yaml: invalid key: "OrderedDict([('count', None)])"
in "/config/include/script.yaml", line 645, column 0