I configured my ESP32 (DOIT ESP32 DEVKIT V1) by loading the bootloader (.bin file) and the “main.ino” file via arduinoIDE.
In the file “User_config.h” I uncommented the line “#define ZgatewayBT” BT “// ESP8266, ESP32” to use my ESP32 as a BLE gateway for NUT and the line // # define ZmqttDiscovery “HADiscovery” // ESP8266, Arduino , ESP32, Sonoff RF Bridge
The process was successful and I can see the RSSI of the NUTmini in the MQTT broker
Having to use the NUTmini for home presence, how can I enable the payload that sees the status of the NUTmini in home and not_home (or on and off) to integrate it into Home Assistant?
I think the home presence option is also only valid for using different room presence detection, but not for presence and non-presence detection. However, I’m not using HA here myself.
For a home and not_home a similar routine might be needed as I’m also using in my openHAB setup.
Regularly check if the beacon is detected/present to have the home status, for this only the unique “Id”: “xx: xx: xx: xx: xx: xx” of the payload is required.
If this regular check in HA does NOT detect the beacon during the regular interval check it sets the not_home status for this beacon.
This allows to set home and not_home for various beacons with their unique Bluetooth MAC addresses (Id in payload)
Or just looking at some other HA configuration.yaml conversation here, does this work for HA with setting
I try the posted code.
I believe it can work in Home Assistant to check for presence in the house.
Is it possible to set a parameter in the sketch or in the .yaml file to make the beacon detect more frequently? It seems to me that it now takes over a minute to check the status.
#ifndef Scan_duration
# define Scan_duration 10000 //define the time for a scan --WARNING-- changing this value can lead to instability on ESP32
#endif
So add the interval and you get an update every 10+interval seconds.
For my setup I use an interval of 10000, so every 20 seconds I get an update.
Hi @DigiH and @1technophile,
I have reviewed the code because the one posted previously did not work well as it did not update the change of state on not_home.
I created these two sensors to be able to monitor presence in Home Assistant.
In my case, I set the status change to NOT HOME after two minutes of inactivity of the RSSI sensor.
sensor:
- platform: mqtt
name: "rssi_nut_openmqttgateway"
unit_of_measurement: 'dBm'
state_topic: 'home/OpenMQTTGateway/BTtoMQTT/XXXXXXXXXX'
value_template: '{{ value_json.rssi | is_defined }}'
- platform: template
sensors:
nut_mini_esp32_openmqttgateway_presence:
friendly_name: "Nut Mini ESP32 Open MQTT Gateway Presence"
value_template: >-
{% set time = states('sensor.time')%}
{% if ( ( ( ( ( as_timestamp(now()) ) - ( as_timestamp( states.sensor['rssi_nut_openmqttgateway'].last_changed) ) | int ) | round(0) ) / 60 ) | int ) <2%}
HOME
{% else %}
NOT HOME
{% endif %}