Detect Power Outage via SNMP Uptime

Hi All,

I would like HA to detect power outage. I don’t have UPS so I intend to rely on the SNMP Uptime output from 5 devices in the house (Printer, Router, Switch, Firewall, HA)

Could you please guide me in the configuration process ? I don’t know how to trigger an even based on the output of 5 sensors. If sensor is less than 1 or 2 minutes the device has rebooted. If all 5 devices are less than 2 minutes we can consider a full power outage

Thank you

1 Like

Hard to see how reliable this would be without something having an independent power supply.

My own solution is to use an old Android phone running a routine created with an app called LlamaLab Automate. I leave it permanently on charge; when the power goes off it sends me an SMS, then another when the power comes on again.

I haven’t tried it, but I believe Automate can be linked to HA. LlamaLab Automate - Home Assistant

To trigger based off multiple things being true, use a template trigger in an automation:


  - platform: template
    value_template: >
     {{ states('sensor.printer_uptime')|int < 120 &&
        states('sensor.router_uptime')|int < 120 &&
        states('sensor.switch_uptime')|int < 120 &&
        states('sensor.firewall_uptime')|int < 120 }}

This assumes your uptime is a simple integer count in seconds.

Nice ! Thank you I will do the test

I found this topic when looking for known methods to restore or set devices to a default state after a power outage.
I have several Zigbee lights that will turn on and they can not be configured to restore to the previous state or to off.

For the readers information, I have added a sensor based on official documentation (the sensors.yaml file is included in configuration.yaml):

- platform: snmp
  name: "Maison Brother uptime"
  accept_errors: true
  unit_of_measurement: "minutes"
  value_template: "{{((value | int) / 6000) | int}}"

That is the only active SNMP service I found.

I also created a scene “state_after_power_outage” where I set the relevant lights to off.

Then I created the automation referencing these two elements:

alias: Power Outage Init
  - platform: homeassistant
    event: start
  - condition: numeric_state
    entity_id: sensor.maison_brother_uptime
    below: '3'
  - service: scene.turn_on
      entity_id: scene.state_after_power_outage
    metadata: {}
mode: single

So basically, this is triggered when HA started, but executes the action only if my printer has been up for less then 3 minutes.

1 Like