I’m using the power output of my pv installation as an outside light sensor. I’ve accomplished this by creating a helper using the threshold sensor and the ‘pv.power’ value of my GoodWe inverter. The problem I’m having is that the GoodWe inverter completely powers down at night causing both the ‘pv.power’ value and thus the output of the threshold sensor to become “unknown”. This makes it rather inconvenient to use it in eg. automations. How can force the threshold sensor to also output “light off” when the input value becomes “unknown” ? I suspect I need to use a sensor-template but I have no idea how to make it work with that.
Yeah use a template sensor instead of the threshold sensor.
configuration.yaml
template:
- binary_sensor:
- name: Outside Light
device_class: light
state: "{{ states('sensor.pv_power')|float(0) > 5 }}"
If the pv power sensor is unavailable its value will be set to the float filter default value, zero in this example: float(0)
, which is going to be less than your set power level (5W in my example above).
The device class will give you a translated state (“Light detected” / “No light”) and pretty icon. See: https://www.home-assistant.io/integrations/binary_sensor/#device-class
Yes, but I also need the hysteresis functionality of the threshold sensor, how can integrate that into the template sensor?
Something like this:
template:
- binary_sensor:
- name: Outside Light
device_class: light
state: >
{% if states('sensor.pv_power')|float(0) <= 5 %}
{{ false }}
{% elif states('sensor.pv_power')|float(0) >= 10 %}
{{ true }}
{% else %}
{{ this.state|bool }}
{% endif %}
This will turn on at 10W and greater, and tun off at 5W or less. Otherwise (between 5W and 10W) it stays the same state as previously determined.
Great, thanks! One thing though: I don’t see it appear in Settings/Entities. I should see it there, right or am I missing something?
You need to restart home assistant.
A great thanks! I only performed a configuration reload but apparently that’s not enough, but now it’s working
The first time you use an integration (e.g. template:
) you have to restart. From now on a reload should be sufficient for newly added templates.