How to Create a
Bee In The Hive
Template Binary Sensor (Without Using the Blueprint)
If you prefer to manually create a Bee In The Hive template binary sensor to fully utilize all features of the Sensor Light Blueprint, use the code below. Add it to your configuration.yaml
file. You will need a File Editor installed into Home Assistant to edit your configuration.yaml
file. For more information on how to install the File Editor add-on Click here
Applying the Changes
After adding your template binary sensor code to your configuration.yaml
file, you have two options to apply the changes:
- Go to
Developer Tools
>YAML
and click Template Entities. - Restart Home Assistant.
Each time you modify the code, youโll need to perform one of these actions for the changes to take effect.
Required Customizations
Make sure to replace the placeholders in the code with your actual entity names:
binary_sensor.your_door_sensor_here
โ Your door contact sensorbinary_sensor.your_motion_sensor_here
โ Your room motion sensor
Optional Customizations
"Bee In The Hive"
โ Choose any name for your new sensor.- Device Class (
"occupancy"
) & Icon ("mdi:account-box-outline"
) โ Customize to fit your preferences. "10"
โ Adjust the door time delay (in seconds) to set how long the system waits after the door closes to allow the motion sensor to clear. Add extra time to ensure the motion sensor properly registers that no motion is detected. See Determine the Door Time Delay below for more information.
The Code
template:
- trigger:
- trigger: state
entity_id: binary_sensor.your_door_sensor_here
to: "on"
- trigger: state
entity_id: binary_sensor.your_door_sensor_here
to: "off"
for:
seconds: 10
- trigger: state
entity_id: binary_sensor.your_motion_sensor_here
to: "on"
binary_sensor:
- name: "Bee In The Hive"
device_class: occupancy
icon: mdi:account-box-outline
state: >
{{ is_state('binary_sensor.your_door_sensor_here', 'off') and is_state('binary_sensor.your_motion_sensor_here', 'on') }}
Testing & Extra Help
1. Determine the Door Time Delay
To set an appropriate Door Time Delay, follow these steps:
- Add your Motion Sensor, Door Sensor, and this Template Binary Sensor to an Entities Card in a dashboard.
- In your dashboard, click Edit, select Add Card, choose the Entities card, add your three entities (motion sensor, door contact sensor, and template binary sensor), then click Save.
This will allow you to monitor and see what is happening. Now, test how long it takes for your Motion Sensor to clear after exiting the room:
- Walk into the room so the motion sensor detects movement.
- Walk out, close the door, and start a stopwatch.
- Observe how long it takes for the motion sensor to return to โclear.โ
Suggested Door Time Delay settings:
- If the sensor clears in 4-5 seconds, set the Door Time Delay to around 10 seconds.
- If the sensor clears in 60 seconds, set the Door Time Delay to around 70 seconds.
Note: You may need to adjust these settings if you experience false readings.
2. Verify the Binary Sensor Stays CLEAR When the Room is Empty
- Walk into the room (motion detected, door open, binary sensor is clear).
- Walk out, close the door, and wait for the motion sensor to clear.
- The binary sensor should remain clear. If it turns to detected, increase the Door Time Delay.
- Fine-tune the delay to prevent false readings.
3. Verify the Binary Sensor Turns DETECTED When the Room is Occupied
- Walk into the room (motion detected, door open, binary sensor is clear).
- Close the door and keep moving inside the room until the Door Time Delay passes.
- The binary sensor should turn to Detected.
- Stay stillโฆ once the motion sensor clears, the binary sensor should remain Detected.
- Open the doorโฆ the binary sensor should turn Clear instantly.
4. Final Test: No Motion, Door Closed, Then Motion Detected
- Walk into the room (motion detected, door open, binary sensor is clear).
- Close the door and stay still so the motion sensor does not detect you.
- Once the Door Time Delay passes and your motion sensor is clear, the binary sensor should remain Clear.
- Move againโฆ when the motion sensor detects motion, the binary sensor should turn Detected instantly.
Your
Bee In The Hive
sensor is now fully set up and ready to use in your automations!
Why Grouping the Sensors is Necessary
When you enter the room and trigger the motion sensor, the light will turn ON as expected based on the blueprint. However, the Bee In The Hive occupancy sensor ensures the light stays ON, even when the motion sensor alone might not detect movement.
By grouping the Motion Sensor with the Bee In The Hive template binary sensor, the automation functions more reliably while allowing you to take full advantage of all Sensor Light Blueprint features. Youโll then use this group as the trigger for your automation. Click here for grouping instructions.
Enjoy
Blacky