@mmiller7 wrote:
I’m trying to make a notification bot for when things happen (e.g. laundry finishes) that any of the authorized telegram users can “request” to be notified (so I don’t have to write every possible combination of automatons, duplicated for every possible user).
I am using hass-variables to successfully store a comma-separated list of people who have requested a notification in a variable:
variable: # Stores list of Telegram IDs to send specified notification to telegram_washer_completed: value: '' restore: true telegram_dryer_completed: value: '' restore: true automation: # Washer Notifications - alias: 'Telegram bot request washer completed alert' trigger: - platform: event event_type: telegram_command event_data: command: '/laundry_notify_washer_completed' action: - service: variable.set_variable data_template: variable: telegram_washer_completed # This mess checks if the value is empty ('') # If it is empty, it just stores # Else, if it has data in it append ", <new_data>" value: >- {% if states.variable.telegram_washer_completed.state == ''%} {{ trigger.event.data.user_id }} {%else%} {{ states.variable.telegram_washer_completed.state }}, {{ trigger.event.data.user_id }} {%endif%} - service: telegram_bot.send_message data_template: target: '{{ trigger.event.data.user_id }}' message: 'Ok, I will notify you next time the washer has completed.'
This seems to work reasonably well and the IDs are stored in the variable separated by commas as suggested by the syntax of the Telegram integration
data_template: target: [CHAT_ID1, CHAT_ID2]
My code does seem to work for 1 single ID in the variable, but if there are 2+ IDs in the variable it gives me errors when it executes
- alias: 'Telegram bot that tells when washer is done' trigger: - platform: state entity_id: variable.washer_state to: 'Completed' condition: condition: template value_template: '{{ states.variable.telegram_washer_completed.state != "" }}' action: - service: telegram_bot.send_message data_template: target: '[ {{ states.variable.telegram_washer_completed.state }} ]' message: 'The washer is finished running.' - service: variable.set_variable data: variable: telegram_washer_completed value: ''
But when it runs with more than one user’s ID in the variable, I get this error:
2020-02-17 11:48:27 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.telegram_bot_that_tells_when_washer_is_available. Invalid data for call_service at pos 1: expected int @ data['target'][0]
Help?
Posts: 17
Participants: 3