I’m a newbie on Home Assistant and I could/would like some help with my automations.
I have a minibieb (Little free libary) that is equiped with a open/close sensor (433 mhz, recieved by a Sonoff RF-bridge running Tasmota). Currently I’ve got two automations, one for when it’s opened and one for when it’s closed.
alias: Melding - Mini bieb (openen)
description: ''
trigger:
- platform: state
entity_id: binary_sensor.mini_bieb
to: 'on'
condition: []
action:
- service: notify.telegram
data:
message: Test
data:
photo:
- url: 'http://10.25.10.90/Streaming/channels/1/picture'
authentication: digest
username:
password:
caption: De mini bieb wordt geopend
mode: single
This automation sends a picture through Telegram informing us the libary is being opened.
My second automation is:
alias: Melding - Mini bieb (sluiten)
description: ''
trigger:
- platform: state
entity_id: binary_sensor.mini_bieb
to: 'off'
condition: []
action:
- service: notify.telegram
data:
message: De mini bieb wordt gesloten
mode: single
This is informing us that the libary is being closed.
Instead of two automations I would like to have one automation, accomplishing the same.
- alias: Melding - Mini bieb (openen/sluiten)
mode: single
trigger:
- platform: state
entity_id: binary_sensor.mini_bieb
action:
- service: notify.telegram
data:
message: Test
data:
photo:
- url: 'http://10.25.10.90/Streaming/channels/1/picture'
authentication: digest
username:
password:
caption: >-
{% if trigger.to_state.state == 'on' %}
De mini bieb wordt geopend
{% else %}
De mini bieb wordt gesloten
{% endif %}
Via de UI was ik op dit gekomen en dat werkt ook, die van jou is wel wat compacter./
Through the UI I created this and it seems to work, yours is a bit more compact.
alias: Melding - Minibieb
description: ''
trigger:
- platform: state
entity_id: binary_sensor.mini_bieb
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.mini_bieb
state: 'on'
sequence:
- service: notify.telegram
data:
message: Test
data:
photo:
- url: 'http://10.25.10.90/Streaming/channels/1/picture'
authentication: digest
username:
password:
caption: De mini bieb wordt geopend
- conditions:
- condition: state
entity_id: binary_sensor.mini_bieb
state: 'off'
sequence:
- service: notify.telegram
data:
message: De mini bieb wordt gesloten
default: []
mode: single
Ik heb jouw code geprobeerd maar krijg een melding:/
I’ve tried your code but got an error:
Message malformed: expected dictionary
Wel jammer dat je vrij weinig gegevens krijgt omtrent waar het fout gaat./
It’s kind of sad that you don’t get that much info about where the error fails.
The automation from @poudenes is not going to do what you want as it will send a picture no matter if it is open or closed and as I understand you only want a picture when it gets opened.
The automation you posted can be made a little more compact by using shorthand conditions and removing the empty condition and default action, otherwise you can’t make it more compact.
alias: Melding - Minibieb
description: ''
trigger:
- platform: state
entity_id: binary_sensor.mini_bieb
action:
- choose:
- conditions: "{{ states('binary_sensor.mini_bieb') == 'on' }}"
sequence:
- service: notify.telegram
data:
message: Test
data:
photo:
- url: 'http://10.25.10.90/Streaming/channels/1/picture'
authentication: digest
username:
password:
caption: De mini bieb wordt geopend
- conditions: "{{ states('binary_sensor.mini_bieb') == 'off' }}"
sequence:
- service: notify.telegram
data:
message: De mini bieb wordt gesloten
mode: single