Set boolean based on equation

I have no doubt that this has been answered before but I am apparently not using the right search terms. I suppose I should also mention that I recently switched from Vera to HA so I am still very much a beginner on the learning curve with HA.

I have a number of automations that I want to apply a condition to based on the Lux reported from a light sensor. It occurs to me that in the long run, referring to a more generic boolean value, say named “dark” would be simpler than constantly referencing a specific light sensor and testing if the value is below a certain number. This is even more so the case since I quickly realized that I want a light sensor that is far more active in updating the Lux value than the battery operated one I have now so I will be changing the sensor I want to use in the automations and if I had the aforementioned boolean value set up I’d only have to change the device reference in that one item instead of in each of the automations I create that use the value.

So can someone point me in the right direction with how I should go about doing this?

Thanks in advance.

Create a Template Binary Sensor that reports on when it’s dark (when your light sensor’s value is below a threshold you’ve chosen), otherwise it reports off. The resulting Template Binary Sensor can be referenced in automations, scripts, etc.

Example

The following configuration defines an entity named binary_sensor.is_dark

template:
  - binary_sensor:
      - name: Is Dark
        state: "{{ states('sensor.your_light_sensor') | int(0) < 50 }}"

wow, that was too easy - well, for someone that has a clue what they are doing. I was thinking it’d be more complicated than that.

TYVM!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.