Hi
I can’t pass a variable into an automation that uses select_option
Automatisation
alias: Test Tempo HP Blanc
description: ""
triggers:
- trigger: state
entity_id:
- sensor.electricite_teleinfo_tarif_en_cours_texte
variables:
tariff: Blanc HP
conditions:
- condition: state
entity_id: sensor.electricite_teleinfo_tarif_en_cours_texte
state: "9"
actions:
- target:
entity_id: select.electricite_pompe_puisard_energie_jour
data:
option: "{{ tariff }}"
action: select.select_option
mode: single
Utility_meter
###############################################
############### UTILITY METERS #################
################################################
utility_meter:
electricite_pompe_puisard_energie_jour:
source: sensor.electricite_energie_pompe_puisard_index_total_kwh
name: Electricite pompe_puisard Energie Jour
cycle: daily
tariffs:
- Bleu HP
- Bleu HC
- Blanc HP
- Blanc HC
- Rouge HP
- Rouge HC
alias: Test Tempo HP Blanc
description: ""
triggers:
- trigger: state
entity_id:
- sensor.electricite_teleinfo_tarif_en_cours_texte
variables:
tariff: Blanc HP
conditions:
- condition: state
entity_id: sensor.electricite_teleinfo_tarif_en_cours_texte
state: "9"
actions:
- target:
entity_id: select.electricite_pompe_puisard_energie_jour
data:
option: Blanc HP
action: select.select_option
mode: single
This solution requires many lines of code for all entities and I would like to use a variable.
Initially I used the following code which worked for several months
Afaik you can use a variable, and the debug output suggests the template is expanded. The problem is that you did not set a variable named tariff, so what is passed to the service is empty.
Where should the variable come from? is the value contained in an entity? If so, you do not need a variable, you can get the state from the entity.
But your question isn’t very clear, because wht you had was a template for an entity id, and what you were trying was a template for an option.
I’m not sure, but I think the variable exists only in the trigger. But for these cases, many use the trigger id to relay information to the action block:
alias: Test Tempo HP Blanc
description: ""
triggers:
- trigger: state
entity_id:
- sensor.electricite_teleinfo_tarif_en_cours_texte
id: "Blanc HP"
conditions:
- condition: state
entity_id: sensor.electricite_teleinfo_tarif_en_cours_texte
state: "9"
actions:
- target:
entity_id: select.electricite_pompe_puisard_energie_jour
data:
option: Blanc HP
action: select.select_option
- target:
entity_id: select.electricite_pompe_puisard_energie_semaine
data:
option: " {{ trigger.id }}"
action: select.select_option
mode: single
Looking at the flow diagram of the trace you shared it appears that you are using the “Run” function. When doing that, or using the automation.trigger action, the trigger and condition blocks are skipped… so the trigger-attached variable you have set up is not instantiated and holds no value. The automation looks fine, it’s your testing procedure that is letting you down.