Currently when one of the doors in my house are open I send a mobile_app notification with the following data:
{
"message": "FYI: door/gate open for 30+ minutes
}
I’d like it to actually say which sensor triggered the automation, eg.
In pseudocode:
if triggered == binary_sensor.0x00fdghgfhgfh5646c_contact
“message”: "FYI: front door open for 30+ minutes
if triggered == binary_sensor.0x00158d05446545416_contact
“message”: "FYI: kitchen door open for 30+ minutes
Additionally, I’d like to append, e.g. if both are open once the second one triggers, it should say
“message”: "FYI: front door, kitchen door open for 30+ minutes
I’m not too familiar with jinja templating (yes I’ve looked at the template wiki), an example from someone who did something similar is way more useful
That would almost do the trick, however for the WAF I’d like to have just Kitchen Door, i.e. a defined even friendlier string per entity. Is it possible to add a custom attribute for this to the entity or do I need to resort to an if else clause
Edit: Adding a custom attribute in the Customizations could work in this case. This doesn’t solve the appending of open doors question though.
I mean, gotta know what trigger you plan on using. Triggers have different properties and that will change how this template will work.
Also, appending the doors in question shouldn’t be a top priority. I’ve been using door notifications for 3 ears and have something similar to this and I have never hit a situation where 2 doors are open at the same time.
Trying this out now and getting the following error:
Error rendering data template: UndefinedError: 'str object' has no attribute 'attributes'
My automation:
- id: 'Test trigger template'
alias: Alert Doors Open TEST
trigger:
- entity_id: binary_sensor.0x00158d0002c6698c_contact
for: 00:00:05
platform: state
to: 'on'
- entity_id: binary_sensor.0x00158d00029b6ed4_contact
for: 00:00:05
platform: state
to: 'on'
- entity_id: binary_sensor.0x00158d00029c4938_contact
for: 00:00:05
platform: state
to: 'on'
- entity_id: binary_sensor.0x00158d0002d70a9f_contact
for: 00:00:05
platform: state
to: 'on'
condition: []
action:
- service: notify.mobile_app_skyg6
data_template:
message: >
"{{ trigger.entity_id.attributes.friendlier_name }} has been open for 30+ minutes."
Also tried without the double quotes, same error. Any ideas?
p.s. I created a custom attribute ‘friendlier_name’ to show a proper name (using friendly_name gives the same error)
First thing that comes to mind is either using stats/history stats and measure the time it is open (max 40 min in the past or so), if you then have an automation with a trigger when the status changes to closed, check in the condition whether the (history) stats is 30+min.
Probably easier to just flip a boolean to on when something is open for 30 min, use that in the condition and next to the message push you flip the boolean back to off.