AppDaemon Q&A

Thanks very much :slight_smile:

I’m trying to get the time passed since the last update of a sensor with the following code:
lsensor_time_since_updated = self.datetime() - self.convert_utc(self.get_state(self.light_sensor, "last_updated"))

Unfortunately, convert_utc seems to fail with:
lsensor_time_since_updated = self.datetime() - self.convert_utc(self.get_state(self.light_sensor, "last_updated"))

Any tips?

self.get_state(self.light_sensor, “last_updated”) gives probably a string.
and self.convert_utc() could need a time

i think you should look in that direction.

(didnt look anything up right now, API could tell you more)

Nope, the api says that the parameter is a string :-\

try self.log(self.get_state(self.light_sensor, “last_updated”) )
and see if in the log you get
An ISO 8601 encoded date and time string in the following format: 2016-07-13T14:24:02.040658-04:00

if not then thats the problem.

I am trying to handle weather underground alerts and I was not sure how such can be implemented when dealing with attributes and which are not guaranteed to exist all the time. Some more discussion is going on here in this thread

alias: "Weather Warning Tornado"
trigger:
  - platform: numeric_state
    entity_id: sensor.pws_alerts
    above: 1
condition:
   condition: or
   conditions:
     - condition: template
       value_template: '{{ states.sensor.pws_alerts.attributes.Description == "Tornado Warning" }}'
     - condition: template
       value_template: '{{ states.sensor.pws_alerts.attributes.Description_TOR == "Tornado Warning" }}'
action:
  service: script.weather_warning_tornado
1 Like

I’d be interested to see how you do this as it seems a better use case for AD than for traditional automation because of all the different alert condition types.

Let me know if you need help. I’ve been playing in AD lately with Weather Underground’s forecast data so I’m in the neighborhood so to speak.

1 Like

@turboc, thanks for the offer, let see how much good I can describe what I need.

I have AppDaemon app that listen to change on Weather Underground alert changes but want to filter those alerts to most critical one like tornado, hail etc but not like fog advisory as I have audio announcement using Google cast devices and definitely do not want to wake middle of the night just for fog alert but would like to for tornado.

sensor.pws_alerts is just number of active alerts but in order to get type of alerts looks like we need to check attributes but depending on the number of active alert the attribute(s) formulated differently as mentioned in the other discussion thread.

My goal is to notify via audio and text notifications on certain types of alerts but not all, I have notification code/app working but trying to figure out (need help) how to identify specific alerts which I am interested in. May be in future Weather Underground component alert sensor will have better way to see the alert types.

May be I can use hasattr() function to check presence of each possible values like Description_TOR, Description_SEW?

Thanks all

1 Like

something like this?

tornadowarning = ""
your_sensor =
your_attribute =
try:
  tornadowarning = self.get_state(your_sensor,your_atrribute)
except:
  self.log("tornado attribute doesnt exist")
if tornadowarning != "":
  notify me

as callback from a run_every

1 Like

I’m guessing you are using the API as described on this page

https://www.wunderground.com/weather/api/d/docs?d=data/alerts#city_within_the_usa

Nice, this should work. I will have few of this kind of try/except to check the alerts I am interested and go on from there.

I will be putting this code under state change event so I will not have to call using run_every() function for efficiency.

Let me work on this changes this week-end and once working/tested, I will post code here so it can benefit some else too.
Thanks @ReneTode

1 Like

Side topic here. This is another example where I wish I had a scroller or something where alerts like this could be scrolled across the HA screen. Like a scrolling persistent notification.

changing the frontend is not really my thing :wink:
but i can think of ways to get a scrolling notification in dashboard :wink:

@scadaguru your welcome.

yea there are a few issues with dashboard that I haven’t gotten back to. It works, but doesn’t display some of the things the way I want them displayed. The bug hasn’t bitten me to figure them out over there yet.

But back to this topic. I have a AD app that will take a list of items from the AppDaemon config file as parameters that are the types of alerts we are interested in (so it’s configurable). It then scrolls through any alerts out there and for the ones we are interested in, it currently displays them to the log, although from there we could dump the to speech, or to a control in HA.

Sound like what we want?

another thing I found that might help. In addition to the alert type, there is a significance field that could be leveraged as well.

W Warning
A Watch
Y Advisory
S Statement
F Forecast
O Outlook
N Synopsis

Nice, this is good information but HA component is not capturing this information so it will not be available to HA or AD.
May be we can put feature request for this. Here is the link to that PDF file from Weather Underground which shows details about this significance field.

http://www.nws.noaa.gov/os/vtec/pdfs/VTEC_explanation6.pdf

If you don’t mind sharing that AD app will be nice.
Thanks

Ok, still working on it. Trying to make sure it doesn’t duplicate alerts now and need to set up callback to repeat checks every so often.

The problem is that WeatherUnderground doesn’t give the alerts a unique key. So I have to generate a repeatable unique key for each alert, build a list of the ones I have reported, and then clean it up after the alerts expire so you don’t get alerted for the same thing multiple times. Maintaining that list is giving me a little trouble at the moment. It’s the whole list/dictionary thing. I sure miss arrays. LOL