Sensor templates and arrays of values

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?

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.

Can you paste a screenshot from the Developer Tools / States screen? Like this, but for your switch:

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.

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.

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

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 }}

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 :stuck_out_tongue:

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