ian.robson
(Ian Robson)
November 25, 2021, 2:31am
1
I am just getting started in HA so sorry if this has been asked before but I could not find an answer. I am trying to set the value of a input_text from a group of lights and it appears to be working but when I try to display it in the log file I get an error
Error: Error rendering data template: UndefinedError: ‘input_text’ is undefined.
Also when i try to toggle the device after the log file message I get the identity_id as unknown.
I think it is my syntax that is the problem and my limited understanding of yaml
The code I am using is as below
data_template:
entity_id: input_text.light_to_switch
value: '{{ states.group.simulation_lights.attributes.entity_id | random }}'
- service: logbook.log
data:
name: Notice..
message: Random Away Lights Step 2 '{{input_text.light_to_switch}}'
- service: homeassistant.toggle
data_template:
entity_id: '{{states(''input_text.light_to_switch'')}}' ```
tom_l
November 25, 2021, 3:24am
2
This is not how you access the state of an entity:
'{{input_text.light_to_switch}}'
This is:
"{{ states('input_text.light_to_switch') }}"
I suggest you have a read of this:
There are lots of examples.
Also your indentation is not correct. Should be:
- service: logbook.log
data:
name: Notice..
message: Random Away Lights Step 2 '{{states('input_text.light_to_switch')}}'
1 Like
ian.robson
(Ian Robson)
November 25, 2021, 3:01pm
3
Thank you for pointing me in the correct direction. I will read it and let you know how I get on. Once again thank you
ian.robson
(Ian Robson)
November 25, 2021, 4:22pm
4
Once again Thank you but I still seem to be having a problem. The value set for input_text.light_to_switch is for example light.foyer which I can see in the debug step details. however when i call it in the log as in your example I get the value of unknown. I was looking at the examples and tried .value on the end but still get unknown.
tom_l
November 25, 2021, 9:55pm
5
Nowhere does it say to do that.
Please show what you have now.
ian.robson
(Ian Robson)
November 26, 2021, 1:38am
6
This is what I have at the moment and the results I am getting.
- service: input_text.set_value
data_template:
entity_id: input_text.light_to_switch
value: '{{ states.group.simulation_lights.attributes.entity_id | random }}'
- service: logbook.log
data_template:
name: Notice..
message: Random Away Lights Step 2 '{{states('input_text.light_to_switch')}}'
- service: homeassistant.toggle
data_template:
entity_id: '{{states(''input_text.light_to_switch'')}}'
The first service shows the following result
Executed: November 25, 2021, 8:15:00 PM
Result:
params:
domain: input_text
service: set_value
service_data:
entity_id: input_text.light_to_switch
value: light.kitchen_light
target: {}
running_script: false
limit: 10
However the log shows the following unknown not light.kitchen_light the value set on service 1
Notice… Random Away Lights Step 2 ‘unknown’
Hence the third service fails to toggle as it too has unknown not light.kitchen_light
Executed: November 25, 2021, 8:30:00 PM
Result:
params:
domain: homeassistant
service: toggle
service_data:
entity_id: unknown
target: {}
tom_l
November 26, 2021, 2:17am
7
What does this show as the result in the Developer tools Template editor:
{{states('input_text.light_to_switch')}}
Also, try this:
- service: homeassistant.toggle
target:
entity_id: '{{states(''input_text.light_to_switch'')}}'
And you dont need to use data_template:
any more. Just data:
will do.
1 Like
ian.robson
(Ian Robson)
November 26, 2021, 2:21am
8
{{states(‘input_text.light_to_switch’)}} in developer tools shows unknown
tom_l
November 26, 2021, 3:36am
9
That’s your problem then.
Either you have not got the correct entity id (check in Developer Tools / States) or it has no state set.
EDIT: I’ve just noticed how you are setting the input_text. Try this instead:
- service: input_text.set_value
target:
entity_id: input_text.light_to_switch
data:
value: '{{ states.group.simulation_lights.attributes.entity_id | random }}'
1 Like
ian.robson
(Ian Robson)
November 26, 2021, 4:06am
10
I could not find the entity_id input_text.light_to_switch in the developer tools. I re added it in helpers and now it is working perfectly. Thank you so much for all your help.
1 Like