Auto-entities: template lightning strikes of last hour?

trust me, I am trying. And am, aamof. But this is not that simple as you say.
I am hoping to find a way to have the auto-entities card show the lightning strikes of the last hour.

I cant check right now, because no strikes are registered, but your template counts the strikes.

next to that, the format of the filter of the auto-entities card requires yet another different syntax. Have only made a few of these, relying on a simple state (as posted above) makes me want to seek help of the community…

I don’t think you can do what you want to do with auto-entities. It doesn’t appear as if you can match state object properties with this card. @thomasloven would know for certain if there is a way to match against last_updated property (which is not an attribute). I doubt it because they are datetime objects.

You may be able to make an automation that updates minutely and dynamically changes the entities inside a group. Then use auto-entities match group as a card.

Using the service: group.set

Yes, feared as much on the last updated. But maybe the attribute publication_date could come to the rescue? compare that to now and have set of states built on that?

How? Templating isn’t available in auto-entities.

bummer. you’re right…I’ve mistaken

  • supports Regular Expressions.
  • supports comparison operators
    for templating…

so need a feature request before I can build it than :wink:

as discussed here Jinja / Template Sensor Question - #11 by Mariusthvdb I would have hoped to create a template likewise for the last hour end have auto entities show them.

{% set km = states('input_number.lightning_strikes_near') %}
          {{ states.geo_location|selectattr('attributes.source','eq','wwlln')
             |selectattr('state','lessthan',km)|list}}

Or make a dynamic group with an automation. Then use said dynamic group as the match group for auto-entities.

I’ll have a look at that, as said, theses are only my first auto-entities cards.

This all wouldn’t be necessary if the integration wwlln: would simply work as described of course. window and radius not really effective, and seems the UI integration only uses window, which doesn’t work (yet, dev’s are working on that)

…yet…
 

2 Likes

I agree. Personally, I don’t know why the lightning strikes were added as separate sensors. I would expect these to be attributes which would allow easy templating.

While Thomas is adding templating (yeah) I had a look at my domains sensor, and that would translate to something like this:

{%- set t = as_timestamp(now()) - 60 * 60 %}
{%- for s in states.geo_location %}
{%- if s.entity_id.attributes.source == 'wwnnl' and s.last_updated != None and as_timestamp(s.last_updated) > t %}
{%- endif %}- {{s}}
{%- endfor %}

cant test it now, because no lightnings are around, but am not sure of the {{s}}.
Would that show the full entity, thuis building the list I require?

{{ s.entity_id }}{{ ',' if not loop.last else ''}}{%- endif %}
1 Like

think it also needs to be:

{%- if s.attributes.source == 'wwlln' and s.last_updated != None and as_timestamp(s.last_updated) > t %}

instead of

{%- if s.entity_id.attributes.source == 'wwllln' and s.last_updated != None and as_timestamp(s.last_updated) > t %}

making it

{%- set t = as_timestamp(now()) - 60 * 60 %}
{%- for s in states.geo_location %}
{%- if s.attributes.source == 'wwlln and s.last_updated != None and as_timestamp(s.last_updated) > t %}
{{ s.entity_id }}{{ ',' if not loop.last else ''}}{%- endif %}
{%- endfor %}

now wait for the strikes to happen and test.

I didn’t notice the entity_id in there.

That template should just create a list of entity_id’s. Where are you using it?

but only of the domain geo_location and source wwnnl. Which get created if and when lightning is registered. Currently they aren’t there, so no list is created.

not yet using it, but as said, hope to be able to use it somehow in the Lovelace frontend. Will use it with source usgs_earthquakes_feed also.

most likely use it for Map, because I need an entity list there. If I can get the Maps card to be templated, and then replace this:

  - type: conditional
    conditions:
      - entity: binary_sensor.lightning_active
        state: 'on'
    card:
      type: map
#      dark_mode: true
      title: Lightning strikes conditional map
      geo_location_sources:
        - wwlln

marked your post as solution, it shows fine after the discussed edits above!

this is it:

{%- set t = as_timestamp(now()) - 60 * 60 %}
{%- for s in states.geo_location %}
{%- if s.attributes.source == 'wwlln' and s.last_updated != None and as_timestamp(s.last_updated) > t %}
{{ s.entity_id }}{{ ',' if not loop.last else ''}}{%- endif %}
{%- endfor %}

just a bit more variation:

trying this:

          {% set hour = states('input_number.strikes_period')|float %}
          {%- set t = as_timestamp(now()) - hour*(60 * 60) %}
          {%- for s in states.geo_location %}
          {%- if s.attributes.source == 'wwlln' and s.last_updated != None and as_timestamp(s.last_updated) > t %}
          {{ s.entity_id }}{{ ',' if not loop.last else ''}}{%- endif %}
          {%- endfor %}

to create an option to have an input_number in the front-end allow me to see the when most of the strikes happened.

first I tried it without the |float on hour, but then I realized even an input_number isnt a number, but a string…

what I hadn’t noticed before at all, is that all input_numbers have a state with a decimal number. Even if the minimum step is an int. And still are strings…
confusing.

secondly, and most importantly, it adds the , even after loop.last with makes the full template fail in the frontend.

somehow is doesnt see the last as last, because no matter what I enter in the else clause, is isnt displayed, instead a , is used.

print loop.last out and see what it’s value is

will do, but have to wait for a few strikes to happen.

btw, this was a full listing, took extra care to set the hour so that is showed only a few strikes.

Hey guys. Sorry but wwlln is no more :frowning: https://github.com/CCOSTAN/Home-AssistantConfig/issues/392