Tuya: Device Offline Alert

Hi there!

I have 73 Tuya devices currently, all connected through a specific 2.4GHz network used only for IoT. Connection is somewhat stable, but when a power failure occurs (and they happen frequently) one or two devices won’t come back - I have to enter the smart life app and see the ones not connected to reset them.

Well, I would like to automate this task without having for example to define a ping sensor for each one of these devices.

Any suggestions?

Thanks in advance!

the state in homeassistant doesn’t swtich to report ‘unavailable’? mine does when they go offline…

In fact, it does… right now I have an ekaza smart plug 20A that is offline / unavailable… But how do I create an automation that reports that and how do I make an automation that would work with all tuya devices at once (the idea is to avoid creating an automation for each device)…

it depends on what exactly you want to do.

so for example, you could do this:

description: ""
mode: single
trigger:
  - platform: template
    value_template: >-
      {{ integration_entities('tuya') | expand |  selectattr('state', 'eq',
      'unavailable') | list | count > 0 }}
condition: []
action:
  - service: script.debugmsg
    metadata: {}
    data:
      debugtrace: offline
      title: tuya device offline
      message: >-
        here are the list of offline devices

        {{ integration_entities('tuya') | expand |  selectattr('state', 'eq',
        'unavailable') | map(attribute='name') | list  }}

this will trigger when a device serviced by the 'tuya" integration gets the status ‘unavailable’ and call a service (debugmsg) with the list of all integrations that are unavailable

a few things to note

  1. remember all triggers fire when the trigger goes from not true to true. so this triggers when the count goes from 0 to non-zero. if you have a bunch offline now, it won’t trigger. but depending on exactly what you want to do, you can muck with this general notion and likely get what you want.
  2. the script.debugmsg is my own personal helper script. i’m just using this an example. you’d replace it with whatever you want.
  3. this uses ‘tuya’ integration. you should replace that with whatever integration you’re using… e.g. ‘localtuya’ or whatever.

i’m not clear on exactly what you want your automation to do, but hopefully this helps get you going in the right direction…

1 Like

It does! Thank you!