My goal is the create a custom binary sensor which passes the value of a motion sensor only when the light are on of the living room. (So I would like to use the motion sensor only when the lights are ‘on’).
I have tried several different implementation for the template but do not seem to get it working. I made an automation which works well, but within the automation I can not set a binary sensor
I would like to get some support why my implementation is not working as expected:
I tried several different variations
with and without quotes in the “logic statement”
with “state” and “value_template”
legacy and new convention for binary sensors
as a triggered and state binary sensor
restarted home assistant
removed “and” logic
placed “(” and “)” to group logic
in developer tool > templates it is working as expected
PS Most probably it is something very stupid, but apparently I overlook it completely.
It seems that none of my binary sensor helpers created via the GUI are working. If I place the same code into configuration.yaml (by including binary_sensors.yaml) it starts working as expected (for the ones created in the yaml file and not via the GUI)
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template: !include binary_sensor.yaml
Updated the title of the post to match current issue
This is most likely wrong, the template integration can create binary sensors, but there’s also a binary_sensor integration, so this is at least confusing. What is in the binary_sensors.yaml, templates or binary sensors?
Also, you talk of adding things in the gui, but the examples you post are pure yaml, not intended for the gui (where you only post the jinja2 template for the value, not the entire definition).
And also note, if you put definitions in an include file like above, you need to remove the topmost level in the file: that is already stated outside the file. So the quoted line assumes what is in the file is what belongs under template: (so that should no longer be in the file at top level).
If you put it in yaml, then you need to check the config for errors first (which I assume would have given errors from what you posted), and if there are no errors you need to restart. If you edit template sensors in the GUI that is not needed, but then you need only supply the value template, not all the rest.
Thanks as well ! Understood that if you include a file you need to take care of that. As indicated this was working properly.
Like you also suggested I just needed to add the jinja and not the whole yaml code. Rookie mistake.
Naming the include file that contains template definitions binary_sensor.yaml is still an accident waiting to happen and will likely lead to more weird errors that will be hard to spot.