pvklink
(peter van Klink)
December 1, 2023, 7:27am
1
Is it possible to use a variable in a variable for attribute m1 as part of a sensor?
I want to use the states part as part of a notification and set the m1 attribute name within variables
"{{ states['sensor.melding'].attributes.m1 }}"
not working line 4
{% set another = 'm1' %}
{{ another }}
works {{states['sensor.melding'].attributes.m1}}
not working {{states['sensor.melding'].attributes.'{{another}}'}}
pvklink
(peter van Klink)
December 1, 2023, 7:37am
2
found it !
more of a lucky shot!
{% set another = 'm1' %}
{{ another }}
{{ states['sensor.melding'].attributes[another] }}
and this is a part of where it all comes together
alias: visite
icon: mdi:party-popper
variables:
berichtid: m5
keuze: "{{ keuze if keuze is defined else states('input_boolean.visite') }}"
mode: "{{ iif(keuze == 'on', 'off', 'on') }}"
avond: "{{ states('input_boolean.scene_avond') }}"
dagtype: "{{ dagtype if dagtype is defined else states('input_select.dagtypen') }}"
actiontrigger: "{{ actiontrigger if actiontrigger is defined else 'niet gespecificeerd' }}"
actionstate: "{{ actionstate if actionstate is defined else 'niet gespecificeerd' }}"
sequence:
- service: variable.update_sensor
data:
replace_attributes: false
attributes:
'{{berichtid}}': test7m5
target:
entity_id: sensor.melding
enabled: true
- service: script.turn_on
data:
variables:
bericht_id: "{{ states['sensor.melding'].attributes[berichtid] }}"
bericht_logtype: debug
bericht_titel: xvisite (script)
bericht_inhoud:
keuze: "{{keuze}}"
mode: "{{mode}}"
avond: "{{avond}}"
dagtype: "{{dagtype}}"
actiontrigger: "{{actiontrigger}}"
actionstate: "{{actionstate}}"
target:
entity_id: script.default_bericht
enabled: true