finity69x2 / nws_alerts

An updated version of the nws_alerts custom integration for Home Assistant
84 stars 29 forks source link

Request expiration timestamp be added #37

Closed philbert2k closed 2 years ago

philbert2k commented 2 years ago

In the older version where there was two separate automations / sensors that would expose expiration field of the alert, example below. Is there any way to get it added back so it can be referenced in automations/templates.

{{
    as_timestamp(state_attr('sensor.nws_alert_event',
    'features')[0].properties.expires)| timestamp_custom('%-I:%M %p on
    %-m-%-d-%Y') }}.
finity69x2 commented 2 years ago

that was never a part of this custom integration.

It was a part of the older non-integration code that I used in the beginning.

it is still available by using a REST sensor to get the entire json structure of the alerts then pull whatever you want from it.

here is the REST sensor code example:

- platform: rest
    resource: https://api.weather.gov/alerts/active?zone=<YOUR_ZONE_INFO>
    name: NWS Alert Event
    value_template: >
      {% if value_json.features[0] is defined %}
        {{ value_json['features'][0]['properties'].event }}
      {% else %}
        None
      {% endif %}
    json_attributes:
      - features
    headers:
      User-Agent: Homeassistant
      Accept: application/geo+json
    scan_interval: 60

then use your code above to get the expiration data.