Getting started with templates!

Hi!

I’m trying to get the hang of templates for my setup and would like some help.

I have a Sonoff connected to the alarm output of my burner.

If the Sonoff have status “unavailable” the burner is working properly. If the Sonoff change status to “off” or “on” the alarm output is active, indicating an error.

If I include the device (“light.burner”) in the UI I get an device that mostly state “unavailable”.

I would like to like to create a virtual sensor that instead is “off” when the status of the device is “unavailable” and “on” when the device either has the status “on” or “off”.

How would the syntax for this look?

Should be something like this:

binary_sensor:
  - platform: template
    sensors:
      burner_is_on:
        value_template: >-
          {{ states.light.burner.state  == 'unavailable'}}

So when light.burner is unavailable it will render as binary_sensor.burner_is_on as true/on and when it is not available it will be false/off.

That’s a very strange way of setting things up. I’m assuming your burner has an alarm relay output and you are using that to switch the power to the sonoff on or off?

A better way of connecting this would be to power the sonnof all the time and connect the burner alarm relay (must be voltage free contacts!!) to one of the sonoff GPIOs.

As a bonus you also now have the switched sonoff power output you can use to control a device nearby.

Yes, I realise it’s a bit weird setup!

I only had a Sonoff Basic laying around and the burner gives 220V when the alarm relay output is active.

I have a relay laying around I could use but I don’t know how the voltage free output from the relay would be connected to the Sonoff? Would this require dismantling the Sonoff and soldering?

Thank you @bradyn12! So that kind of simple templates always gives true/on when the condition (state in this case) is fulfilled?

I thought it might have been something like that.

Yes but it is incredibly simple and there are plenty of guides on line.

@bradyn12’s template sensor should work.