Check for offline or missing sensor

I was wondering if anyone had a good way check or create a sensor that checks if one of my sensors is online.

For some reason when my solar sensor (current power) is offline the whole sensor goes away rather than having a nil reading. I have searched a bit on the forums however cannot find one that is for this scenario. Most are checking if nil readings, rather than the actual sensor itself being missing.

Thanks

I am interested in detecting if one of my mqtt sensors is missing too. Hopefully there is a good solution!

Have a read through this for the concept and refinement of the one I use…

Thanks for the reply @anon43302295 I am sure your solution would have worked but was a little too much for me to follow.

@hmoffatt I ended up doing it a different way, I guess it might to be the prettiest way… I just created a new sensor that senses the other sensor. So the sensor that keeps going missing for me is sensor.power_ac_fronius_inverter_1_http_192_168_1_85

Then I added the following to my sensors.yaml:

  - platform: template
    sensors:
      fronius_energy_current_kwh:
        friendly_name: 'Current Energy'
        unit_of_measurement: 'W'
        value_template: "{{(states('sensor.power_ac_fronius_inverter_1_http_192_168_1_85'))}}"
        icon_template: mdi:solar-power

Then the new sensor created sensor.fronius_energy_current_kwh gives me the “unknown” reply if it is offline/missing.

That way I can use conditional controls when I need to; ie. state or state_not

Hope this helps someone else. If anyone has another simple idea or better way than me, I am happy to hear it :slight_smile: