Counting how often a sensor became unavailable

Hi,

I have a ventialtion system in my house which is shut off quite often automatically as it is connected to a low pressure warning device which cuts the power at the socket. I have installed a Shelly plug s to it to get notified once the power is off and the shelly becomes unavailable. Now I would like to have a sensor that counts how often the sensor becomes unavailable (i.e. the system is shut down) per day, week, month etc.

What would be the best way to tackle this?

Thanks very much in advance!

Option1: create a input helper that updates with each ‘unavailable’
Option2: run SQL on the db
Possibly other options …these are my 2cts

Hi @vingerha,

how would the input helper version look like? I have actually not worked with helpers yet.

You create an input helper (counter) via devices > helpers
Then you create an automation that triggers on the sensor state, and if state ‘unavailable’ … updating the helper via service ‘increment …’

Hi,

I have created this now:

alias: Abschaltung Lüftungsanlage
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.luftungsanlage_power
    to: unavailable
condition: []
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.abschaltungen_luftungsanlage
mode: single

I’ll leave this running now until the next time the ventilation system becomes unavailable to check if the helper increases by one.

You do not have to wait, you can manually set the state to unavailable using the development tools > states …and check the result

Working!

Thank you very much for your help @vingerha. That helped me also to understand a little bit more about helpers :slight_smile: