Skip to content

Commit

Permalink
mailbox sensors and automation
Browse files Browse the repository at this point in the history
  • Loading branch information
matt8707 committed Nov 4, 2021
1 parent 62b807c commit 95b4797
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/automation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,39 @@ automation:
{% else %}
{{ media_players | selectattr('state','eq','playing') | map(attribute='name') | max }}
{% endif %}
- alias: mailbox_count
id: '2878459556162'
mode: restart
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.aqara_contact_count
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.aqara_contact_reset
from: 'off'
to: 'on'
condition:
- condition: template
value_template: >
{{ as_timestamp(now()) - as_timestamp(state_attr('automation.mailbox_count',
'last_triggered')) > 7 or trigger.entity_id == 'binary_sensor.aqara_contact_reset' }}
action:
- choose:
- conditions: >
{{ trigger.entity_id == 'binary_sensor.aqara_contact_reset' }}
sequence:
- service: mqtt.publish
data:
topic: homeassistant/persistence/mailbox
payload: 0
retain: true
default:
- service: mqtt.publish
data:
topic: homeassistant/persistence/mailbox
payload_template: >
{{ states('sensor.mailbox') | int + 1 }}
retain: true
5 changes: 5 additions & 0 deletions include/sensor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ sensor:
state_topic: !secret switchbot_mqtt_battery
unit_of_measurement: '%'


- platform: mqtt
name: mailbox
state_topic: homeassistant/persistence/mailbox

- platform: command_line
name: imac_ip
command: !secret imac_ip
Expand Down
5 changes: 5 additions & 0 deletions include/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ template:
<font color='#6a7377'>Allt är avstängt</font>
{%- endif -%}
</b>
mailbox: |
{% set mailbox = states('sensor.mailbox') %}
{% if mailbox | int > 0 %}
{{ '\U0001F4EC' }} <font color='#6a7377'><b>Brevlåda ({{ mailbox }})</b></font>
{% endif %}
vacuum: |
{% set entity_id = 'vacuum.morty' %}
{%- if is_state(entity_id, 'cleaning') -%}
Expand Down

0 comments on commit 95b4797

Please sign in to comment.