Tuya SOS button state

According to this list the Tuya SOS emergency button is formally supported by the Tuya integration.
I bought one from my aging mother. Via the Tuya smart app you get a notification every time the button is pushed. The downside is if you miss this single notification the event might go unnoticed for hours. Therefore I implemented an automation to notify every minute until acknowledged.
The problem I have in HA is that the button state goeas from safe to unsafe at the first event and never returns to safe again until I restart HA. Is there a way to reset this state from inside the automation? I tried the service homeassistant.turn_off but this does not work.

1 Like

Hi Marc, Did you sort this out? I just received the panic button and I am not able to catch the event in Home assistant? Can you share your trick?

Hi @jani.vehkalahti

I just used the Tuya integration but it is still not working stable. I am hoping a future update will improve this

Hi Marc,
Any news homeassistant.turn_off?
Is there a way to reset this state from inside the automation?

I believe I know the answer to the issue stated above.

I recently purchased two of these devices (Tuya Zigbee Wireless Remote Call SOS/Emergency Button) for my folks and connected them via ZHA using a ConBee II stick on an ODROID-N2+. They work great, but they do not work like a typical button.

Firstly, it appears that they only trigger to an “on” state of triggered (correct me if i’m wrong). It also looks like it sends a burst of “on” or “triggered” signals. My best guess is that it is to ensure that the signal is received. The side effect is that you can’t just turn-it-off/toggle it by pressing the button again (for whatever reason), but I tackle that issue further down
.
Secondly, the buttons show up as an alarm_control_panel entity, not a switch.

Additionally, the buttons also have a default passcode of “1234”, which we’ll need to know when we disarm it (aka: turn it “off”).

Discovering this, I have been able to programmatically reset the SOS buttons via an automation by calling the service alarm_control_panel.alarm_disarm (where the entity_id is the ID of the alarm_control_panel button - see sample script at the end for proper usage). This will reset the buttons from a triggered state (“on”) to disarmed state (“off”).


IMPORTANT:

You will need to send the alarm passcode in order for that to work, otherwise it will remain triggered until the system is restarted (based on what I’ve read, a system restart will reset the entity, but I haven’t needed to reboot to reset it, so I cannot say for certain).

That is your answer:
Treat the buttons as an alarm_control_panel.

However, if you want to use the same button to toggle the button state ON and OFF (triggered and disarmed, respectively), then continue reading to see what I did for a work around.


NOTE:
It appears that the button does not resend triggered signal once it is triggered. I don’t think it sends any signal while in triggered mode. This means that it cannot be triggered a second/third/fourth/etc. time-in-a-row while in the triggered state and therefore cannot be used to re-trigger an automation until it is disarmed (aka: off). This means it cannot be toggled/disarmed (turned off) with a second press. Not without some work, anyway.

Ergo “some work”:
What I did to work around this is the following solution (the below assumes you are familiar enough with Home Assistant to understand how to YAML code or create it via the UI ):

  1. Create a boolean switch (a binary helper will work).
  2. Create an automation/script to toggle the boolean switch when triggered by the button’s “triggered” state.

An important note:

When capturing the button’s triggering event, be sure to specify that you’re looking for a state FROM “disarmed” and TO “triggered”. Otherwise you risk this automation being triggered again as it gets programmatically disarmed (turned off). This would be like turning a light switch off and immediately back on again, which would defeat the purpose. So we only want to trigger it going in one direction, not both. This is when I realized that it was also sending out a burst of “triggered” signals, which is why I had to use the trigger-timer. I hope that makes sense… okay, moving forward here…

Before we can use the automation code, we need to make sure we have an input_boolean created for it.

input_boolean:
  sos_button_1:
    name: SOS Button 1
    icon: mdi:hospital

Once we have that in place, reboot Home Assistant. After it comes back up, create a new automation with the following code below.

NOTE:

You’ll need to replace the entity_id with the name of your Tuya button’s ID. Mine was named alarm_control_panel.sos_button_01_trigger, so just replace that with yours. If you didn’t alter the input_boolean code above, you’ll be okay to leave that alone.

alias: SOS trigger
# NOTE: You can remove the descriptive-text below if you'd like, 
# but I find it helpful when I come back later and try to figure
# out what/why I did what I did.
description: >-
  When the Tuya SOS button is pressed, it triggers this automation. This
  automation toggles the state of an input_boolean, aptly named
  SOS Button 01 (input_boolean.sos_button_1), and then resets the 
  Tuya SOS button's state to "disarmed".

  Any other automations needing a binary on/off state should be
  triggered from the input_boolean (not the button itself).

  The reason for this funky mess is because the Tuya SOS button
  appears to be an  "ON" only trigger, and therefore (apparently) cannot
  be toggled off by a button press. Furthermore, when it is pressed,
  it appears to send out a burst of signals to turn it ON and force it
  into a "triggered" state.  That created issues with this automation
  in that it would get triggered several times before remaining on or off. 
  To combat this, I've utilized the timer option within the trigger
  itself.  I imagine that each system using this will run differently, so
  you may need to increase or decrease the time, but for me, a three
  second pause seemed to do the trick on my system.

  Also noteworthy - ALLOW THE AUTOMATION TO COMPLETE!
  If you interrupt the automation before it sets the button back into a
  "disarmed" state, then this automation will no longer run due to the
  "FROM: disarmed" and "TO: triggered" conditional requirements
  we've set.

  There may be a better/more appropriate way to do this, but it's after
  midnight right now, and i'm kinda brain-fried...
trigger:
  - platform: state
    entity_id:
      # this is the actual Tuya button entity. Replace this one with
      # YOUR entity
      - alarm_control_panel.sos_button_01_trigger
    from: disarmed
    to: triggered
    for:
      hours: 0
      minutes: 0
      seconds: 3
condition: []
action:
  - if:
      - condition: state
        # This is the input_boolean we created with the first,
        # small-chunk of code.
        # Leave as is unless you've changed the name in the code.
        entity_id: input_boolean.sos_button_1
        state: 'off'
    then:
      # turn ON input_boolean - must have this here
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.sos_button_1

      # do stuff
      - service: tts.cloud_say
        data:
          entity_id: media_player.google_mini_04
          message: SOS 1 turning on

    else:
      # turn OFF input_boolean - must have this here
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.sos_button_1

      # undo stuff
      - service: tts.cloud_say
        data:
          entity_id: media_player.google_mini_04
          message: SOS 1 turning off

  - service: alarm_control_panel.alarm_disarm
    # MUST HAVE THIS SERVICE - failure to disarm the Tuya button will 
    # prevent this automation from running due to our trigger requirements.
    # NOTE: This is OUTSIDE of the If/Then/Else block. This service needs
    # to be triggered every time so that the "triggered" state is reset to
    # "disarmed", otherwise this automation will never run after it is
    # first triggered.
    data:
      # Don't forget that we MUST INCLUDE the passcode here, otherwise 
      # (to reiterate) the alarm will simply remain in a
      # "triggered" state, and this automation will not run
      # after its first trigger.
      code: '1234'
    target:
      # this is the actual Tuya button entity. Replace this one with
      # YOUR entity
      entity_id: alarm_control_panel.sos_button_01_trigger
mode: single



For a bit more clarity, the service we call at the end of the script will disarm the button’s triggered state, thereby resetting it. By disarming it, we allow a new button press to trigger the automation the next time it is pressed. Otherwise, the button will remain “on” (triggered) and the automation will not trigger again any time afterwards.

The process above is basically taking an “on only” switch and turning it into an “on/off” switch, aka: a toggle. The thing you have to remember is that if you need both “on/off” states, you’ll have to use the input_boolean.sos_button_1 that we created at the beginning.

I don’t know if this will help anyone, and I hope it makes sense. This may also be better used in a sensor of some kind, but I haven’t worked through that yet. When I do, i’ll update/add it here.

Good luck!

1 Like

Hi, I have just the same problem. In Home Assistant Tuya integration I can get only the Battery % value. Is it possible to get the button state jus using Smart Life?
Thanks

1 Like

Same here, I can only get battery. Did you find a way to solve that?