palengh
(Pål Engh)
April 28, 2020, 12:18pm
1
I had this running for a couple of days now, but it does not change the value of the binary_sensor
.
sensor.pir_utetrapp_luminance
is truely reporting luminance back in lux, as expected, and it updates regularely.
What I want is the sensor
to change state (from false
to true
) when the luminance is below 50 lux. Obviously it has been darker than 50 lux last night.
binary_sensor:
- platform: template
sensors:
dark_outside: ### Set the sensor to true if luminance is below 50 at exerior stairs
entity_id: sensor.pir_utetrapp_luminance
friendly_name: Mørkt utendørs
value_template: >-
{{ states('sensor.pir_utetrapp_luminance')|float < 50 }}
tom_l
April 28, 2020, 12:53pm
2
That looks ok to me, assuming that first line only appears once in your config, and that the entity_id is correct.
Have you restarted home assistant since defining the sensor?
palengh
(Pål Engh)
April 28, 2020, 12:56pm
4
This binary_sensor
is within a package. I do have a /config/binary_sensor.yaml
, which is empty too…
123
(Taras)
April 28, 2020, 1:01pm
5
Just for fun, paste the template into the Template Editor.
Cover sensor.pir_utetrapp_luminance
so its luminance value falls below 50. Refresh the Template Editor and confirm it reports True
.
Uncover the sensor, refresh the editor, confirm it reports False
.
tom_l
April 28, 2020, 1:01pm
6
Ok as long as that only appears once in the package.
Did you include the package?
palengh
(Pål Engh)
April 28, 2020, 1:48pm
8
123:
Cover sensor.pir_utetrapp_luminance
so its luminance value falls below 50. Refresh the Template Editor and confirm it reports True
.
Uncover the sensor, refresh the editor, confirm it reports False
.
This works too…
Maybe there were som hick-up last night. I wait another 24h to see what happends here…
Both these triggered as well, pushing notification to my phone.
- alias: '[House] Det er mørkt ute'
initial_state: 'on'
trigger:
platform: state
entity_id: binary_sensor.dark_outside
to: 'on'
action:
- service: notify.adults
data:
title: 'Home Assistant'
message: 'Det er mørkt ute, kl. {{now().strftime("%H:%M")}}'
- alias: '[House] Det er lyst ute'
initial_state: 'on'
trigger:
platform: state
entity_id: binary_sensor.dark_outside
to: 'off'
action:
- service: notify.adults
data:
title: 'Home Assistant'
message: 'Det er lyst ute, kl. {{now().strftime("%H:%M")}}'
123
(Taras)
April 28, 2020, 2:06pm
9
What does the binary_sensor’s history show for last night?
I know this might not help your original issue, but using a template without using data_template:
still feels incorrect (though using the notify service, this seems to be ‘overlooked’…)
use:
action:
- service: notify.adults
data_template:
title: 'Home Assistant'
message: 'Det er lyst ute, kl. {{now().strftime("%H:%M")}}'
2 Likes
palengh
(Pål Engh)
April 28, 2020, 2:27pm
11
The binary_sensor.dark_outside
reported off
for the last 24 hours. Av
is Off
value_template: >-
{{ states('sensor.pir_utetrapp_luminance')|float < 50 }}
The binary_sensor.dark_inside
reported on
between 20:36 and 06:52, which seems reasonable På
is On
value_template: >-
{{ states('sensor.pir_utetrapp_luminance')|float < 150 }}
palengh
(Pål Engh)
April 28, 2020, 2:37pm
12
You´re right. Thank you for your heads-up
123
(Taras)
April 28, 2020, 2:48pm
13
The two dark sensors uses different thresholds for reporting darkness (50 and 150).
The one using a threshold of 150 reports correctly but the one using 50 does not. Can you confirm that the luminance value really does fall below 50 during the night? The scale of the graph you posted makes it difficult to see that.
palengh
(Pål Engh)
April 28, 2020, 2:49pm
14
And for the record: Here are the two sensors:
binary_sensor:
- platform: template
sensors:
dark_outside: ### Set the sensor to true if luminance is below 50 at exerior stairs
entity_id: sensor.pir_utetrapp_luminance
friendly_name: Mørkt utendørs
value_template: >-
{{ states('sensor.pir_utetrapp_luminance')|float < 50 }}
icon_template: >-
{% if is_state('binary_sensor.dark_outside', 'on') %}
mdi:weather-night
{% else %}
mdi:weather-sunny
{% endif %}
dark_inside: ### Set the sensor to true if luminance is below 100 at exerior stairs
entity_id: sensor.pir_utetrapp_luminance
friendly_name: Mørkt innendørs
value_template: >-
{{ states('sensor.pir_utetrapp_luminance')|float < 150 }}
icon_template: >-
{% if is_state('binary_sensor.dark_inside', 'on') %}
mdi:weather-night
{% else %}
mdi:weather-sunny
{% endif %}
palengh
(Pål Engh)
April 28, 2020, 2:54pm
15
There you go!
It seems to stop at 55
But still I need this to turn the exterior lights on when the light is around 50
123
(Taras)
April 28, 2020, 2:59pm
16
palengh:
It seems to stop at 55
If it stops at 55 then that explains why the Template Binary Sensor never reports on
(because it uses a threshold of 50).
Change the threshold value to 60.
palengh
(Pål Engh)
April 28, 2020, 3:13pm
17
I will definitely play with that value.
Fun fact: We are soon to experience sunsets as late as 22:30, which will make this even tougher.
in your case, a look at the binary_sensor threshold might be useful. you can set an upper and lower threshold, and a window to that threshold.
minimum config in your case
binary_sensor:
- platform: threshold
entity_id: sensor.pir_utetrapp_luminance
lower: 50
I use these for my appliances. they’re always on, so on/off is not of interest, but the power consumption checks to see if they are at work:
very nice and very trustworthy (of course, only if the base sensor is)
123
(Taras)
April 29, 2020, 1:10pm
19
Did increasing the threshold to 60 fix the problem?
palengh
(Pål Engh)
April 29, 2020, 3:50pm
20
I am not sure if that made the trick, or if the main problem was the sensor was not reporting correctly the night before. Last night the luminance dropped to 36 lux, first time at 21:19.
As you can see the sensor.pir_utetrapp_luminance
(Utetrapp) sensor set the binary_sensor.dark_outside
correctly last night, as opposed to the night before (earlier post/screen dump).
I guess the scripts and automations are working now.
Thank you for your help on this guys