nielsfaber / alarmo

Easy to use alarm system integration for Home Assistant
1.38k stars 120 forks source link

Telegram notification on alarm triggered #266

Closed raelbsd closed 3 years ago

raelbsd commented 3 years ago

Hi, I'm running in circles with this issue, I don't know if I have something misconfigured. I've a few binary sensors for checking the backyard, my HA's Telegram setup it's ok and working. When I define in Actions a notification to fire a Telegram message, it works fine with arming and disarming, but I've no luck with the alarm triggered notification. It doesn't send anything, if I change it to a push notificatoin works thru the HA's app, but I need to send it to my Telegram group. I don't know if its a bug or I'm missing something beyond my sight.

I'm running Alarmo v1.6.2 and HA core-2021.7.2. Also HACS 1.13.2. Thanks in advance for you help.

nielsfaber commented 3 years ago

Please share your configured action.

You say the telegram notification does work for arming/disarming events, but not for alarm triggered? Are there any differences (other than the event)? Does it work if you click the ‘try’ button in the action editor?

raelbsd commented 3 years ago

Hi, I'm attaching my notifications and the one isn't working. I've deleted them and recreate with the same results. If I click the try button works, and when the sensor detect motion the lovelace card shows the alarm triggered, and my action is fired. But the notification isn't sent to the Telegram group. Thanks alarmo1 alarmo2

zollek commented 3 years ago

Hi, I've the same problem (using v1.7.2) Notifications doen't work for events: Alarm is triggered, Failed to arm and Entry delay started.

I've noticed erros in my log:

2021-08-19 23:02:44 ERROR (SyncWorker_4) [homeassistant.components.telegram_bot] Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 71. Args: (1701177116, 'ALARM\nAlarm zostal uruchomiony! Powod Czujnik_Otwarcia_Okno_Sypialnia_3_contact is open.'), kwargs: {'parse_mode': 'Markdown', 'disable_web_page_preview': None, 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

2021-08-19 23:04:21 ERROR (SyncWorker_2) [homeassistant.components.telegram_bot] Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 109. Args: (1701177116, 'ALARM !! Nieudana proba uzbrojenia !\nNie udalo sie uzbroic alarmu z powodu Czujnik_Otwarcia_Okno_Sypialnia_3_contact is open.'), kwargs: {'parse_mode': 'Markdown', 'disable_web_page_preview': None, 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

2021-08-19 23:22:41 ERROR (SyncWorker_0) [homeassistant.components.telegram_bot] Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 109. Args: (1701177116, 'ALARM !! Nieudana proba uzbrojenia !\nNie udalo sie uzbroic alarmu z powodu Czujnik_Otwarcia_Okno_Sypialnia_3_contact is open.'), kwargs: {'parse_mode': 'Markdown', 'disable_web_page_preview': None, 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

Automations work (checked on the light switch on when alarm trigered). Notification added as a HA automation works as well.

Also noticed, that Modes doesn't save. Save button works but after reopen notiication, there's no mode.

Any idea how to repair alarmo notifications?

raelbsd commented 3 years ago

Hi, I found that the alarm triggered notification works fine thru the mobile app notify, but isn't working thru telegram. Also checked the telegram notification added as an HA automation and it works. Other notifications are working, I only have problems with the alarm triggered notification and with telegram. Alarm Armed and Disarmed are sending telegram messages. The alarmo automation works (I have a light switch too), and I also noticed that Modes don't save. Thanks

nielsfaber commented 3 years ago

I don't have Telegram Notify services available for testing. If you could share your YAML configuration of the notification action, I could test if the task is stored and triggered correctly. Alarmo doesn't do much other than calling the service as it was provided by the user. So there is not anything specific to Telegram or other platform in the code.

raelbsd commented 3 years ago

The notification action's YAML is on the /config/custom_components/alarmo folder? In which file? I didn't change anything there, and all configuration I made was thru the GUI, I didn't found there anything related to my config. Sorry for the dumb question, thanks

nielsfaber commented 3 years ago

No, I mean the action as you have set it up in the notification editor. There is a button in 'task' where you can switch between UI and YAML view: image

I'd like to see the YAML version of your notification, then I could check if all is configured OK and copy it locally for testing.

zollek commented 3 years ago

Hi, YAML should be ok, it works when I press TRY IT and looks like this:

service: notify.telegram_zollek
service_data:
  title: ALARM
  message: Alarm zostal uruchomiony! Powod {{open_sensors}}.

image

I'm sending You full alarmo settings file to see, that there is no difference between notifications except of event that triggers it. I've changed user code to: 1111 alarmo.storage.txt

nielsfaber commented 3 years ago

dzenkuje! I will check it out.

zollek commented 3 years ago

It's more like dziękuję, but You're close enough :-) And I should thank You for taking time to help us :-)

nielsfaber commented 3 years ago

First I set up the notification to trigger a persistent_notification: image

Yaml config:

service: notify.persistent_notification
service_data:
  title: ALARM
  message: Alarm zostal uruchomiony! Powod {{open_sensors}}.

With a logging message at the place where Alarmo calls the service:

2021-08-20 19:28:29 DEBUG (MainThread) [custom_components.alarmo.automations] {'service': 'notify.persistent_notification', 'data': {'title': 'ALARM', 'message': 'Alarm zostal uruchomiony! Powod Back Door is open.'}}

Result: image

Then I repeated the same with your configuration (I had to do this manually since for me telegram.zollek doesn't exist):

service: notify.telegram_zollek
service_data:
  title: ALARM
  message: Alarm zostal uruchomiony! Powod {{open_sensors}}.

Result:

2021-08-20 19:32:59 DEBUG (MainThread) [custom_components.alarmo.automations] {'service': 'notify.telegram_zollek', 'data': {'title': 'ALARM', 'message': 'Alarm zostal uruchomiony! Powod Back Door is open.'}},
2021-08-20 19:32:59 ERROR (MainThread) [homeassistant.util.logging] Exception in async_alarm_state_changed when dispatching 'alarmo_state_updated': ('1623385299', 'pending', 'triggered'),
Traceback (most recent call last):,
  File "/config/custom_components/alarmo/automations.py", line 97, in async_alarm_state_changed,
    await self.async_execute_automation(automation_id, alarm_entity),
  File "/config/custom_components/alarmo/automations.py", line 191, in async_execute_automation,
    await async_call_from_config(,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 165, in async_call_from_config,
    await hass.services.async_call(**params, blocking=blocking, context=context),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1439, in async_call,
    raise ServiceNotFound(domain, service) from None,
homeassistant.exceptions.ServiceNotFound: Unable to find service notify.telegram_zollek,
,

I don't see anything wrong from Alarmo side, the service is executed as it is provided by the user. Could it be that the telegram service needs different parameters or something?

zollek commented 3 years ago

I've done some more testing. The reason it doesn' work any more is because of the sensor list {{open_sensors}}. When I delete this command, everything works just right. So the problem aren't events but massage containig sensor list. So sending massage: ALARM! Alarm zostal uruchomiony! on Alarm is triggered event works just right but when I change it to: ALARM! Alarm zostal uruchomiony! Powod {{open_sensors}}. message newer comes and I get the the log error:

Logger: homeassistant.components.telegram_bot
Source: components/telegram_bot/__init__.py:586
Integration: Telegram bot (documentation, issues)
First occurred: 20:05:46 (1 occurrences)
Last logged: 20:05:46

Error sending message: Can't parse entities: can't find end of the entity starting at byte offset 78. Args: (1701177116, 'ALARM\nALARM! Alarm zostal uruchomiony! Powod Czujnik_Otwarcia_Okno_Sypialnia_3_contact is open.'), kwargs: {'parse_mode': 'Markdown', 'disable_web_page_preview': None, 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}
nielsfaber commented 3 years ago

I think the problem is that your entity is missing a 'Friendly Name', apparently Czujnik_Otwarcia_Okno_Sypialnia_3_contact is not allowed in text. I assume you have an entity binary_sensor.Czujnik_Otwarcia_Okno_Sypialnia_3_contact, in Configuration -> Entities you should be able to assign it a readable name. There is also the option in Alarmo to assign a name to each sensor instead.

You can try sending the same message from HA directly: image

I assume (if you set Telegram as target) it will result in the same error (see HA logs).

zollek commented 3 years ago

You're right !! The problem is that the message contains default entity name and from some reason it generates an error. I've looked at previouse telegram messages and when I've recived it, it looked like:

ALARM! Alarm zostal uruchomiony! Powod CzujnikOtwarciaOknoSypialnia3contact is open.

It was missing _ sign.

Setting up sensor friendly name in Alarmo sensor settings fixed the problem. Strange is that before yesterday update I did get messages. Maybe something changed in HA, I've updated HA, OS and all the integrations.

Thanks for Your help and time :-) For me this topic can be closed.

raelbsd commented 3 years ago

Hi, I've replaced the names of the sensors, stripping the underscores ("_") in the names and worked! Thank you guys for your time and effort, this issue is closed for me too.