Make a 'conditional sensor'

Hi folks. Going well beyond comfort zone here, which is fun. Bear with me.

I’d like to create a sensor to mirror a second sensor, and have it enabled or disabled based on the state of a third sensor. In Excel language (cos that’s the best I can do):

S1=IF(S3=On,S2,0)

(the use case, if helpful, is that I want to monitor electricity usage split into cheap rate and peak rate buckets. This isn’t regular-time-based but in slots as chosen by the supplier (Octopus) and indicated as a sensor via an api. Unfortunately Octopus is unable accurately to report the data buckets I need, so I need a workaround)

I’ve had a look at the various Helpers available and searched this forum. Can anyone point me in the right direction?

Thanks in advance

Template sensor helper with a state template of:

{{ iif(is_state('binary_sensor.s3','on'), states('sensor.s2'), 0) }}

(with your real sensor IDs substituted in)

Docs for the sensor:

All about templates:

1 Like

Thank you so much, I’ll give it a go!