My objective is to automate a few things based on any of a range of mqtt_room sensors (one or more) being in a given room at any given time.
Here’s the setup I have:
I have an ESP32 board set up with ESPresense and communicating over mqtt. It’s device messages are integrated with HA as sensors under the mqtt_room platform. I have several individual devices tracked and integration as below:
The room where the ESP32 is set up appears in mqtt under the topic: espresense/rooms/office.
I have validated the setup works and the history of all the sensors is correct, stating office or not_home at the appropriate times.
As stated, I’d like to automate a few things based on any of the sensors being in the room at a given time. I don’t care which sensor is there, what I care for is whether there is at least one or none.
How would I best approach this?
I was thinking of incrementing/decrementing a counter helper entity with one automation every time one of the devices would enter/leave the room. I could then use the count state itself to drive further automations (eg. turn lights on/off, etc etc). Is that an appropriate approach?
My problem is that binary_sensor.office_occupied is not showing although I already created sensor_office.yaml and I already restarted HA, I’m missing something…
That’s a lot to read and assimilate
What’s the easiest way of doing this? Can’t I add all the templates in one file instead of creating a bunch of files with a template for each room?
In the thread you sent my you have a lot of files:
templates.yaml
template_sensors.yaml
template_binary_sensors.yaml
Help me breaking this out please.
First I add to configuration.yaml:
template: !include templates.yaml
In templates.yaml I just need to put this because I don’t have template_sensors:
You already have template: and - binary_sensor: in the include structure if you put it in the file as well you will double up on both of them and get nothing but config errors.
Just one more little question, the automation I’m trying to make work, but I need to use entity instead of device, but in Automations/Actions I can’t find one for entities.
This is what I have for devices:
alias: Test
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.quarto_ocupado
from: "off"
to: "on"
condition: []
action:
- type: turn_on
device_id: b7b8fae214399f40e749a6cf7aebfdf5
entity_id: light.luz_switch_1
domain: light
mode: single