This formula works well in template
{%set qui = 'arnaud' %}
{{states.person[qui].last_changed.timestamp()}}
How to write this in an automation without an error
- service: input_text.set_value
target:
entity_id: "input_text.{{qui}}_date_dernier_changement"
data_template:
value: >
{%set qui = 'arnaud' %}
{{states.person[qui].last_changed.timestamp()}}
I’ve tried many combinations with data, data_template, value, value_template. None of them works.
Any help would be appreciated.
Regards
pedolsky
(Pedolsky)
2
Use variables
:
description: …
variables:
qui: arnaud
trigger:
…
action:
- service: input_text.set_value
data:
value: '{{ states.person[qui].last_changed.timestamp() }}'
target:
entity_id: input_text.{{qui}}_date_dernier_changement
Thanks a lot but I have still an issue when calling this script.
The script called by an automation
sauvegarde_presence:
sequence:
- variables:
qui: {{ who }}
#
- service: input_text.set_value
target:
entity_id: "input_text.{{qui}}_date_dernier_changement"
data:
value: "{{states.person[qui].last_changed.timestamp()}}"
- service: input_text.set_value
target:
entity_id: "input_text.{{qui}}_etat_dernier_changement"
data:
value: "{{states('person.'~ qui)}}"
and the automation:
action:
- choose:
- conditions:
- condition: template
value_template: "{{(as_timestamp(now(),0)-as_timestamp(states.sensor.uptime.last_changed,0)) | int(0) > 180}}"
- condition: template
value_template: "{{ states('input_text.arnaud_etat_dernier_changement') != states('person.arnaud') }}"
- condition: template
value_template: "{{ states('person.arnaud') != 'unknown'}}"
sequence:
- service: script.sauvegarde_presence
data:
who: 'arnaud'
and the error message
Error loading /config/configuration.yaml: invalid key: "OrderedDict([('who', None)])"
in "/config/integrations/../scripts/Sauvegarde présence.yaml", line 9, column 0
The issue seems to be in the transfer of the parameter from the automation to the script.
Any idea how to solve this ?
Regards
Found !
Sorry . The error is in the syntax of the sripit = quotes forgotten
- variables:
qui: "{{ who }}"
pedolsky
(Pedolsky)
5
If everything is working now, please mark the topic as solved.