how would you set up a automation that triggers when receiving a message from a person on your phone from facebook or whatsapp?
I have added the companion app and gave it permission to read messages on my phone.
There is a sensor now in HA that is called sensor.sm_a520f_last_notification.
It displays multiple attributes, but i dont know how to set them up to trigger a light.
Has anyone done this before?
android.appInfo: ApplicationInfo{8629146 com.whatsapp}
android.icon: 2131231578
android.infoText: null
android.largeIcon: null
android.people: [Ljava.lang.String;@c5f5f07
android.progress: 0
android.progressIndeterminate: false
android.progressMax: 0
android.remoteInputHistory: null
android.showChronometer: false
android.showWhen: true
android.subText: null
android.text: Hi
android.title: Name of Person
is_clearable: true
is_ongoing: false
package: com.whatsapp
post_time: 1640548014471
icon: mdi:bell-ring
friendly_name: SM-A520F Last Notification
Create an automation,
set a trigger to use the state of a device.
Set the entity to sensor.sm_a520f_last_notification
Set the attribute to: package
Set the To field to com.whatsapp
Set a trigger ID eg: whatsapp
Add another trigger doing the same thing, but this time setting To to the package name for Facebook Messenger. And again give it an ID eg facebook
Then in the actions, you can either set it to turn a light on. Or if you have coloured LEDs, you can use choose and set the first choose condition to trigger, and choose whatsapp. Then you can set the colour of the light to eg green. And the second choose option, use trigger, facebook. Then set the light to turn on with for example blue or purple.
Thank you, that worked instantly.
Is it possible to have it for a specific person only?
i tried adding a condition using state sensor.sm_a520f_last_notification
attribute Android.title
State to the persons name, but that doesn’t do anything
{{ 'persons name' in state_attr('sensor.sm_af520f_last_notification','title') }}
that will let you check if the name of the person appears IN the title, whereas using a state condition, means the title has to completely match what you write.
Just noticed that for some reason we have an f in the sensor name that shouldn’t be there, it should be: sensor.sm_a520f_last_notification
not as we (I) currently have it: sensor.sm_af520f_last_notification
wow, that was literally it. You got a good eye to catch that one.
Thank you so much for helping me out on this thing.
I do notice though, that if i receive 2 whatsapp messages it will only turn on the light on the first message.
Only if i receive a facebook one and then a new whatsapp message it will work again.
Not sure why it wont tigger every time.
Because the package has to change TO either the whatsapp or the facebook one. If the last message was from whatsapp and a new message comes in on whatsapp, the package name has not changed, and thus the trigger condition has not been met.
If you want to make it fire on EVERY message. Then you need to remove the to: in the trigger, and instead add it all as a condition.
{{ 'com.whatsapp' in state_attr('sensor.sm_a520f_last_notification','package') or 'com.facebook.orca' in state_attr('sensor.sm_a520f_last_notification','package') }}
that template will replicate what the trigger was doing it, but now it is a condition template.
I should clarify by the way, that you need to remove the attribute too, you want this to trigger on ALL state changes, if you leave the attribute in there, it will only fire on attribute changes, and the same problem will happen, if you get 2 messages from whatsapp, because the attribute won’t change, the automation won’t trigger.
for the final wish would it now be possible to make it seperate AND per person?
meaning a automation for a specific person on facebook and whatsapp?
would i just need to add another condition like ?
{% set pk = state_attr('sensor.sm_a520f_last_notification','package') %}
{{ 'com.whatsapp' in pk or 'com.facebook.orca' in pk }}
{{ 'Kevin' in state_attr('sensor.sm_a520f_last_notification','android.title') }}
You would typically keep the condition as it was, and then in actions use the CHOOSE option. You can then have a set of actions for each CHOOSE condition.
So:
Choose:
condition: {{ ‘Kevin’ in state_attr(‘sensor.sm_a520f_last_notification’,‘android.title’) }}
and then whatever actions you want to perform.
Then you click on “add option”
and add your next person:
condition: {{ ‘Santa’ in state_attr(‘sensor.sm_a520f_last_notification’,‘android.title’) }}