HASS alarm/command that make an Android phone ring, how to?

Hi, I succesfully use Telegram for my HASS notification to my Android phone, and I know I can associate to a Telegram group a specific tone, but I do prefer to receive a full call.

Because for very important alert messages from HASS for me the Telegram text message, even with a specific sound, its not enough, wish to receive something like a call: a not ending sound until I pick up the phone.

Suggestiuons on how to achieve this?

Just make the automation continue to send the notification over and over until you send back an acknowledge. Telegram lets you send back responses to HA

There is a good example of how to use the inline keyboard responses here

mmhh how would you do that, how to repeat an action over and over in automation

Call a script as the action. Get the script to repeat until the condition becomes false (ie: once you send the telegram response). I have an example somewhere but not handy right now unfortunately

I use a priority setting in Pushover (so in the automation in HAss, there is a priority parameter) for when my house alarm goes off. This sound will sound on my phone whatever the state of the phone is (even if on silent or do not disturb)

Always have problems in doing loops, below the code, need to add condition to the automation, but not sure how to do the loop for the script

  - id: alarm_triggered22
    initial_state: 'on'
    alias: 'Triggered'
    trigger:
      - platform: state
        entity_id: alarm_control_panel.house
        to: 'triggered'
    action:
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram
      - service: switch.turn_on


script:
  send_alarm_triggered_telegram:
     sequence:
      - service: telegram_bot.send_message      
        data_template: 
          message: "Hi there, the {{ trigger.to_state.attributes.friendly_name }} triggered the alarm, please go and check on it"
          target: '-385901000'

I’ll dig up my example and post it as soon as I get a chance

thanks not urgent, whenever you can

the first script below can be called as the action of your automation. note that this is just from my collection of code snippets from this forum, not currently in use by me and everything except the ‘script:’ line needs to indented 2 spaces (just due to me copy/pasting from the forum)

script: # the below is not indented correectly relative to this line

alias: Fire Alarm
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.kitchen_speaker, media_player.googlehome1023
          volume_level: '0.90'
      - service: tts.google_say
        data:
          entity_id: media_player.kitchen_speaker, media_player.googlehome1023
          message: 'Fire Alarm, Evacuate'
      - delay:
          seconds: 2
      - service: media_player.play_media
        data:
          entity_id: media_player.kitchen_speaker, media_player.googlehome1023
          media_content_id: https://xxxxxxxxxxxx/local/submarine_diving_alarm.mp3
          media_content_type: 'audio/mp3'
      - delay:
          seconds: 1   
      - service: script.turn_on
        data:
          entity_id: script.fire_alarm_loop
    
   
    alias: Fire Alarm loop
    sequence:
      - delay:
          # time for flash light off
          seconds: 2
      - service: script.turn_on
        data:
          entity_id: script.fire_alarm

in this case the script fires a local sound but you can change it to your notify service

so that’s the script: I put 2 times 2 second delay just in case (I know script have problems with loop otherwise)

script:
  send_alarm_triggered_telegram:
    sequence:
      - service: telegram_bot.send_message      
        data_template: 
          message: "Hi there, the {{ trigger.to_state.attributes.friendly_name }} triggered the alarm, please go and check on it"
          target: '-385901000'
      - delay: '00:00:02'
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram_loop
  send_alarm_triggered_telegram_loop:
    sequence:
      - delay: '00:00:02'
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram

thats the idea… but I think 4 seconds might be a little too fast to be receiving multiple messages on your phone, that will be crazy!

well the idea is to have continuous notifications (like when you receive a call, the ring does not stop, until you answer the phone), but yes maybe 4 seconds … will try

then you also need a condition in there to break the loop once you send the telegram response to acknowledge the notification

Sometrhing like this?

automation:
  - alias: 'Turn off notification in telegram'
    hide_entity: true
    trigger:
      platform: event
      event_type: telegram_callback
      event_data:
        data: '/turnoffnotification'
    action:
      - service: script.turn_off
        entity_id: script.send_alarm_triggered_telegram
      - service: script.turn_off
        entity_id: script.send_alarm_triggered_telegram_loop


script:
  send_alarm_triggered_telegram:
    sequence:
      - service: telegram_bot.send_message      
        data_template: 
          message: "Hi there, the {{ trigger.to_state.attributes.friendly_name }} triggered the alarm, please go and check on it"
          target: '-385901000'
      - service: telegram_bot.send_message
        data_template:
          title: 'Turn OFF this notification?'
          target: '-385901000'
          message: 'Turn OFF this notification?'
          inline_keyboard:
            - "YES:/turnoffnotification"
      - delay: '00:00:04'
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram_loop
  send_alarm_triggered_telegram_loop:
    sequence:
      - delay: '00:00:04'
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram

Almost. The keyboard response needs to be detected using another automation.

input_boolean:
  alarm.telegram:
    name: 'Alarm Telegram Message Enabled'

automation:
  - id: telegram-ik-turnoffnotification
    alias: 'telegram turnoffnotification'
    hide_entity: true
    trigger:
      - platform: event
        event_type: telegram_callback
        event_data:
          data: '/turnoffnotification'
    action:
      service.input_boolean.turn_off
      entity_id: input_boolean.alarm_telegram

script:
  send_alarm_triggered_telegram:
    sequence:
      - service: telegram_bot.send_message      
        data_template: 
          message: "Hi there, the {{ trigger.to_state.attributes.friendly_name }} triggered the alarm, please go and check on it"
          target: '-385901000'
      - service: telegram_bot.send_message
        data_template:
          title: 'Turn OFF this notification?'
          target: '-385901000'
          message: 'Turn OFF this notification?'
          inline_keyboard:
            - "YES:/turnoffnotification"
      - delay: '00:00:04'
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram_loop
  send_alarm_triggered_telegram_loop:
    sequence:
      - condition: state
        entity_id: input_boolean.alarm_telegram
        state: 'on'
      - delay: '00:00:04'
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram

hopefully I captured everything, it’s getting late here :sleeping:

Thanks a lot for your time … I will implement all another day anyway, but curious why I do need that input_boolean.

Good night, here in Europe is midday

Well as far as I know, you need something for the telegram response to switch, and need to allocate an entity_id to it. You then use that to break the loop with the condition. I haven’t yet tried the telegram responses myself so I could be wrong, but that’s how the examples I linked earlier are done. I’m in central Australia and its 2123. Have to get up for work at 0445

Thanks again.

Now will think also how to bring that input_boolean ON after turning it OFF, in case alarm triggers again.

EDIT
Maybe like this: the below automation it will stop the scripts when triggered, and after a minute turn on the input boolean, for a later use

  - alias: 'Turn off notification in telegram'
    initial_state: 'on'
    hide_entity: true
    trigger:
      platform: event
      event_type: telegram_callback
      event_data:
        data: '/turnoffnotification'
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.alarm_telegram
      - delay: '00:01:00'
      - service: input_boolean.turn_on
        entity_id: input_boolean.alarm_telegram

just put it in your main trigger automation:

  - id: alarm_triggered22
    initial_state: 'on'
    alias: 'Triggered'
    trigger:
      - platform: state
        entity_id: alarm_control_panel.house
        to: 'triggered'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.alarm_telegram
      - service: script.turn_on
        entity_id: script.send_alarm_triggered_telegram
      - service: switch.turn_on
1 Like

Since version 0.113 it’s no longer needed to use scripts that call eachother. It is now possible to use a loop.

My setup still uses the input boolean:

input_boolean:
  alarm.telegram:
    name: 'Alarm Telegram Message Enabled'

But now, I have the following 2 automations that take care of everything when one of my smoke detectors triggers (oh, and I combined the message and the off button in a single message):

- alias: "800 - Telegram turn off notification"
  trigger:
    - platform: event
      event_type: telegram_callback
      event_data:
        data: '/turnoffnotification'
  action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.alarm_telegram

- alias: "801 - Telegram alarm triggered"
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id:
        - sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_smoke
        - sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_smoke_2
        - sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_smoke_3
        - sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_smoke_4
        - sensor.heiman_technology_co_ltd_smart_smoke_sensor_hs1sa_z_smoke_5
      to: '2'
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.alarm_telegram
    - service: light.turn_on
      entity_id: all
    - alias: Repeat until disabled
      repeat:
        while:
          - condition: state
            entity_id: input_boolean.alarm_telegram
            state: 'on'
        sequence:
          - service: telegram_bot.send_message
            data_template:
              message: "WARNING!!! {{ trigger.to_state.attributes.friendly_name }} triggered the alarm, please go and check it out."
              target: !secret telegram_chatid
              inline_keyboard:
                - "ALARM OFF:/turnoffnotification"
          - delay: '00:00:04'

2 Likes