@ibennani wrote:
My mission: To assign a numeric value in the last row of the script.
My problem: `value: “{{ counter }}” in the code below does not get an numeric value from counter.
- alias: "Count people at home" initial_state: true trigger: - platform: state entity_id: - device_tracker.galaxynote8 - device_tracker.galaxynote8_2 action: - service_template: >- {%- set counter = 0 %} {%- for device in states.device_tracker %} {%- if device.state == "home" and (device.entity_id == "device_tracker.galaxynote8_2" or device.entity_id == "device_tracker.galaxynote8" ) %} {%- set counter = counter + 1 %} {%- endif %} {%- endfor %} variable.set_variable data: variable: count_pepole_home value: "{{ counter }}"
The code above is ment to count people at home and store the amount of people in a variable using the custom component Variable. That custom component works fine, så that’s not an issue here.
When this automation has ran and when i check variable.count_pepole_home in the entities list, it’s state is not the expected numeric value, it’s the string “{{ counter }}” , but of course without quotes.
If both of us are at home, I’d like the value at the end of the script to be set to 2.
I guess the solution is quite simple when you know where to look.
Any piece of advice or other kind of assistans would be very appreciated.
Posts: 1
Participants: 1