A notify function that does more then just 1 notify

Very good approach but in my case on the frontend, it didn’t retain value.

I assume that’s a template sensor.

Ex:

- platform: template
  sensors:
    apd_notify_message:
      value_template: '{{value}}'
      friendly_name: "AppDaemon Notify Message"

I used the following snippet. I did get the notification via IFTTT but from HA/States I didn’t find the value of this sensor there.

notify.py

import appdaemon.appapi as appapi

class notify(appapi.AppDaemon):

  def initialize(self):
    self.set_state("sensor.apd_notify_message",state=" ")
    self.listen_state(self.send_notify,"sensor.apd_notify_message")

  def send_notify(self, entity, attribute, old, new, kwargs):
    self.log("Updated Sensor reading - Value : " + new)
    self.call_service('ifttt/trigger', event='SR_Home', value1=new)

From my hello app:

self.set_state("sensor.apd_notify_message", state="testing1234567")

Log file:

2017-11-21 16:54:38.071366 INFO notifymessage: Updated Sensor reading - Value : testing1234567
2017-11-21 16:54:38.091301 INFO notifymessage: Updated Sensor reading - Value :

the problem is that you created a sensor in HA.
the app creates the sensor itselve if it doesnt exist.
a template sensor depends on a template. setting that value is a problem.

so remove the template sensor from HA and you are good to go.

1 Like

Wow. I didn’t know that AppDaemon creates the sensor for you. That is so cool.

I changed the code accordingly and it worked flawlessly. Thank you for sharing this snippet. :clap:

1 Like

you can do even more with it if you like.
you can edit and add attributes.

so you can change your code so, that in the sensor attributes you could always see the last 10 messages.
and you could add a time attribute to see the time from the last message
and that you can use to add times to the last 10 message attributes.

how to:

thistime= timestring
self.set_state("sensor.notify_message", state="blabla", attributes={"last_time":thistime})
last_message = self.get_state{"sensor.notify_message")
last_message_time = self.get_state{"sensor.notify_message","last_time")
self.set_state("sensor.notify_message", state="blablabla", attributes={"last_time":thistime, "history1":last_message_time + " " + lastmessage})
1 Like

Thank you for that tip. I modified the function and utilized multiple attributes.

  def send_notify(self, entity, attribute, old, new, kwargs):

    self.log("Updated Sensor value : " + new)
    # always send IFTTT notification
    self.call_service('ifttt/trigger', event='SR_Home', value1=new)

    tts_trigger = self.get_state("sensor.appd_notify_message","announce")
    self.log("Announce value : {}".format(tts_trigger))
    if tts_trigger:
        self.call_service('tts/google_say', entity_id='media_player.living_room_home', message=new)

    ha_trigger = self.get_state("sensor.appd_notify_message","frontend")
    self.log("Frontend value : {}".format(ha_trigger))

    if ha_trigger:
        self.call_service('persistent_notification/create',
            title="Attention", message=new+ " - " + datetime.now().strftime('@ %-I:%M %p') )

From other app:

self.set_state("sensor.appd_notify_message", state="Hello Teddy Good afternoon ", attributes={"announce":False, "frontend":True})

2 Likes

use atrributes as args!
cool!

Would you mind sharing or uploading a complete notify app for appdaemon? And how to integrate this in has to add automations. My idea us to show messages in the dashboard sent by homeassistsnt

i dont think you need an app for that.
i think that what you want is just a template sensor.

So it would be possible to show notifications in dashboard? How would I achieve this Master?

My little project: LCD Display with MQTT and Home-Assistant notifies

lol.
what message would you like to see in the dashboard?

something like this?

sensor:
  - platform: template
      temp_message:
        friendly_name: temp
        value_template: '{%- if states.sensor.temp>25 -%}{{ "wow, it i quite hot here" }}{%- else -%}{{"brrrr, maybe i should put on the heating, because its not really warm now."}}{%- endif -%}'
        entity_id:
          - sensor.temp

Wow… Thanks that helps a lot

that MQTT topic isnt that actually a sensor? (sorry, master has never used MQTT :wink: )

I have an automation which publishes all sensors in has to a topic … I can then listen to thus topic with my LCD display

cant you listen with HA to that topic?

The display is mounted in an ESP… This one is running easyesp with mqtt listener .

i understand that.
but you can listen to MQTT with homeassistant, cant you?
so instead of:

sensor > MQTT > homeassistant you have
homeassistant > MQTT > ESP

but then you can also

homeassistant > MQTT > homeassistant > Dashboard

u r right :slight_smile: will see how I will do that :slight_smile:

Hey @ReneTode , are you still doing this method? Did it work out long-term? I ask because I’m thinking I might do this.

yes, i still use this.
and i am very happy with it.
i even expanded it.

i use
self.set_state(“sensor.notify”, state = message) from 2 different AD versions (so i can use it in AD 1 and the app is only in AD 2)

i use
message = “some text:4:300” to let the message be notified 4 times with 5 minutes in between
message = “Alexa;some text” to let alexa speak the text on default group
message = “Alexa;(living room)some text” to let it speak in the living room
message = “Alexa;(first floor)some text” to let it speak in some group

nice to see that i already use it for 2 years now :wink:

2 Likes