chrizzls
(Chris)
January 27, 2023, 10:59pm
1
Hey Guys,
I feel really stupid but I can’t get this to work & need your help.
I want to use the title of google calendar event to set a value to an input_number.
This is the (working) template:
{{state_attr("calendar.heizung_test","message") | replace (' Grad','')|float(0)}}
As you can see it returns the number 66.
But when I try to use this in a service call to set the input_number I get:
This is how I call the service:
service: input_number.set_value
data_template:
value: "{{ state_attr("calendar.heizung_test","message") | replace (' Grad','')|float(0)}}"
target:
entity_id: input_number.test_thermostat
Any help would be highly appreciated.
Cheers
Chris
petro
(Petro)
January 27, 2023, 11:25pm
2
You’re using the same quotes on the outside of the template as on the inside. Notice how your highlighting is all goofy in your posted code?
value: "{{ state_attr('calendar.heizung_test','message') | replace (' Grad','')|float(0) }}"
1 Like
I have a very similar issue. What is my problem?
- action: input_number.set_value
data_template:
value: >
"{% set boton = expand('button.led_patio_10','button.led_patio_20','button.led_patio_40','button.led_patio_60','button.led_patio_80','button.led_patio_100') |
sort(attribute= 'last_changed', reverse=true) | map(attribute ='entity_id') | first %}
{% if boton = 'button.led_patio_10' %} 10
{% elif boton = 'button.led_patio_20' %} 20
{% elif boton = 'button.led_patio_40' %} 40
{% elif boton = 'button.led_patio_60' %} 60
{% elif boton = 'button.led_patio_80' %} 80
{% elif boton = 'button.led_patio_100' %} 100
{% endif %}"
target:
entity_id: input_number.brillo_led_patio
petro
(Petro)
June 17, 2025, 11:50am
5
You’re using multiline notation and providing exterior quotes. Use one or the other.
That was it (and the missing ==).
Thank you very much.
123
(Taras)
June 17, 2025, 1:05pm
7
If you’re interested, you can simplify the template by taking advantage of the fact that the value you want to report is already part of the button’s entity_id. Just extract the value from the end of the entity_id.
- action: input_number.set_value
target:
entity_id: input_number.brillo_led_patio
data:
value: >
{% set boton = expand('button.led_patio_10','button.led_patio_20','button.led_patio_40','button.led_patio_60','button.led_patio_80','button.led_patio_100')
| sort(attribute='last_changed', reverse=true)
| map(attribute='entity_id') | first %}
{{ boton.split('_')[2] }}
EDIT
Correction. Desired value’s list index is 2 not 1.