I have a switch. entity with an attribute that is an array of values:
entity: switch.bhyve_zone
attribute: watering-program
array:
‘2020-07-10T06:00:00-04:00’
‘2020-07-10T06:25:00-04:00’
‘2020-07-18T06:00:00-04:00’
‘2020-07-18T06:25:00-04:00’
‘2020-07-21T06:00:00-04:00’`
‘2020-07-21T06:25:00-04:00’
‘2020-07-24T06:00:00-04:00’
‘2020-07-24T06:25:00-04:00’
Is there a way with a sensor template to extract each value into an individual sensor? Or even just display the array in one sensor?
123
(Taras)
July 10, 2020, 2:24am
2
Can you confirm that I understood it correctly? The switch.bhyve_zone
has an attribute called watering-program
which contains an array ( a list in python language) whose items are dates and times?
Are you positive it is called watering-program
with a hyphen and not water_program
with an underscore ?
If you are certain it’s a hyphen, paste this into Developer Tools > Template and let me know if it shows all the items in the watering-program
list.
{{ state_attr('switch.bhyve_zone', 'watering-program') }}
If that works, try this and let me know what it reports:
{{ state_attr('switch.bhyve_zone', 'watering-program')[0] }}
Sorry, typo. It’s watering_program.
If I paste “{{ state_attr(‘switch.bhyve_zone’, ‘watering_program’) }}” it returns None.
Troon
(Troon)
July 10, 2020, 2:11pm
5
Can you paste a screenshot from the Developer Tools / States screen? Like this, but for your switch:
123
(Taras)
July 10, 2020, 2:14pm
6
What Troon said; we will need to see a screenshot of the entity as it appears in the States page. The template you tested should have returned some sort of value. The fact it didn’t suggests something may not be quite as you described it to be.
Here ya go!
You know I just noticed now that the watering_program attribute shows up twice and one is null. That’s probably the problem. Not sure why it appears twice…could be an issue with the integration.
123
(Taras)
July 10, 2020, 6:27pm
8
Yeah that’s probably why the template produced nothing.
If you try this it should return the word “drip” thereby confirming you can get attribute values, just not watering_program
.
{{ state_attr('switch.bhyve_zone', 'sprinkler_type') }}
I don’t know which integration is being used but you should submit a bug report for the duplicated watering_program
.
Yep, sprinkler_type returns “drip”. I have a template sensor that works fine for that so definitely a result of the duplicate attribute.
Thanks for your help! I’ll submit a bug report for the custom integration.
petro
(Petro)
July 10, 2020, 7:25pm
10
paste this into the template editor:
{{ states.switch.bhyve_zone.attributes.keys() }}
Then post the result here.
It maybe a child of program_e then, there are a number of parameters after program_e not shown on this output.
1 Like
Troon
(Troon)
July 11, 2020, 6:50am
13
Ooh good shout, hinted at in the docs . Try these:
{{ state_attr('switch.bhyve_zone', 'program_e') }}
and
{{ states.switch.bhyve_zone.attributes.program_e.watering_program }}
123
(Taras)
July 11, 2020, 12:33pm
14
Good call! Several keys are not listed here:
So they must be within
program_e
.
Troon’s second template ought to get the desired instance of watering_program
.
Makes me think that, ideally, the States page should indent the attributes keys to improve clarity.
1 Like
Good catch @CestLaGalere !
@Troon Your totally right…it says right in the docs it’s a child of program_e. Guess I should RTFM
That gives me the data…the formatting is wonky but I should be able to parse it.
Thanks for all your help! Love this community!
2 Likes
And @123 :
{{ (states.switch.bhyve_zone.attributes.program_e.watering_program) [0] }}
{{ (states.switch.bhyve_zone.attributes.program_e.watering_program) [1] }}
etc pull out the individual attributes of the entity!
Awesome work guys. Thanks again!
2 Likes