mKeRix / room-assistant

Presence tracking and more for automation on the room-level
https://www.room-assistant.io
MIT License
1.27k stars 122 forks source link

No State Updates from MQTT for BLE Devices #219

Closed Blink515 closed 4 years ago

Blink515 commented 4 years ago

Describe the bug BLE Devices aren't updating their state information in Home Assistant. Subscribing to the MQTT channel shows no state topics for the devices. Looking at the API entities endpoint provides the correct room location and the Room-Assistant devices are sending their config info to MQTT as expected. The status of the sensor shows online so I'm not sure why the state isn't being sent.

To reproduce Not sure.

Relevant logs No errors in the room-assistant log.

*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
6/10/2020, 6:18:11 PM - info - IntegrationsModule: Loading integrations: home-assistant, bluetooth-low-energy
6/10/2020, 6:18:13 PM - info - NestFactory: Starting Nest application...
6/10/2020, 6:18:16 PM - info - InstanceLoader: AppModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: ConfigModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: NestEmitterModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: IntegrationsModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: HttpModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: DiscoveryModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: HomeAssistantModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: ClusterModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: TerminusModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: ScheduleModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: EntitiesModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: BluetoothLowEnergyModule dependencies initialized
6/10/2020, 6:18:16 PM - info - InstanceLoader: StatusModule dependencies initialized
6/10/2020, 6:18:18 PM - info - RoutesResolver: EntitiesController {/entities}:
6/10/2020, 6:18:18 PM - info - RouterExplorer: Mapped {/entities, GET} route
6/10/2020, 6:18:18 PM - info - RoutesResolver: StatusController {/status}:
6/10/2020, 6:18:18 PM - info - RouterExplorer: Mapped {/status, GET} route
6/10/2020, 6:18:22 PM - info - HomeAssistantService: Successfully connected to MQTT broker at mqtt://192.168.1.67:1883
6/10/2020, 6:18:22 PM - info - ConfigService: Loading configuration from /opt/nodejs/lib/node_modules/room-assistant/dist/config/definitions/default.js, config/RA-Office.yml, config/local.yml
6/10/2020, 6:18:22 PM - debug - EntitiesService: Adding new entity status-cluster-size
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Registering entity room-assistant-office-status-cluster-size under homeassistant/sensor/room-assistant/office-status-cluster-size/config
6/10/2020, 6:18:22 PM - debug - EntitiesService: Adding new entity status-cluster-leader
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Registering entity room-assistant-office-status-cluster-leader under homeassistant/sensor/room-assistant/office-status-cluster-leader/config
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Sending new state 4 for room-assistant-office-status-cluster-size
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Sending new state nerdery for room-assistant-office-status-cluster-leader
6/10/2020, 6:18:22 PM - info - ClusterService: Starting mDNS advertisements and discovery
6/10/2020, 6:18:22 PM - info - NestApplication: Nest application successfully started
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Sending new attributes {"nodes":["bedroom","nerdery","tv-area","office"]} for room-assistant-office-status-cluster-size
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Sending new attributes {"quorumReached":false} for room-assistant-office-status-cluster-leader
6/10/2020, 6:18:22 PM - debug - EntitiesService: Adding new entity ble-c53e5f59c30b-tracker
6/10/2020, 6:18:22 PM - info - HomeAssistantService: Device tracker requires manual setup in Home Assistant with topic: room-assistant/device_tracker/ble-c53e5f59c30b-tracker/state
6/10/2020, 6:18:22 PM - debug - EntitiesService: Adding new entity ble-c53e5f59c30b
6/10/2020, 6:18:22 PM - debug - HomeAssistantService: Registering entity room-assistant-ble-c53e5f59c30b under homeassistant/sensor/room-assistant/ble-c53e5f59c30b/config
6/10/2020, 6:18:23 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 6d0bd8158700 with ID 6d0bd8158700 and RSSI -32
6/10/2020, 6:18:23 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 0200204becfb with ID 0200204becfb and RSSI -72
6/10/2020, 6:18:23 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 5cbac94bd9ba with ID 5cbac94bd9ba and RSSI -41
6/10/2020, 6:18:23 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral nut with ID c53e5f59c30b and RSSI -42
6/10/2020, 6:18:23 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 6892a1299706 with ID 6892a1299706 and RSSI -67
6/10/2020, 6:18:23 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 7a7c3f5ae98a with ID 7a7c3f5ae98a and RSSI -75
6/10/2020, 6:18:24 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral e063da888a36 with ID e063da888a36 and RSSI -95
6/10/2020, 6:18:27 PM - error - ClusterService: dns service error: unknown
6/10/2020, 6:18:27 PM - error - ClusterService: dns service error: unknown
6/10/2020, 6:18:32 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 6a64c3b012f7 with ID 6a64c3b012f7 and RSSI -86
6/10/2020, 6:18:35 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral M720 Triathlon with ID db88edaa8cf3 and RSSI -57
6/10/2020, 6:18:36 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 4bc2863b1947 with ID 4bc2863b1947 and RSSI -88
6/10/2020, 6:18:48 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral 7f3451521446 with ID 7f3451521446 and RSSI -76

Relevant configuration Paste the relevant parts of your configuration below.

local.yml:

bluetoothLowEnergy:
    maxDistance: 5
global:
    instanceName: Office
homeAssistant:
    mqttOptions:
        password: #####
        username: #####

RA-Office.yml:

bluetoothLowEnergy:
    channel: room_presence
    tagOverrides:
        75ea096e9c8943b1893a70d6ac9156ca-0-0:
            name: Brian Phone BLE
        a407b68372ac:
            name: Brian Phone BT
        c53e5f59c30b:
            name: Charger Keys
        f0353aef0684:
            name: Brian Room Location
    whitelist:
    - c53e5f59c30b
    - f0353aef0684
    - a407b68372ac
    - 75ea096e9c8943b1893a70d6ac9156ca-0-0
cluster:
    networkInterface: wlan0
    peerAddresses:
    - 192.168.1.53:6425
    - 192.168.1.214:6425
    - 192.168.1.198:6425
    - 192.168.1.221:6425
    - 192.168.1.212:6425
    port: 6425
    quorum: 5
global:
    integrations:
    - homeAssistant
    - bluetoothLowEnergy
homeAssistant:
    mqttUrl: mqtt://192.168.1.67:1883

Entities API Data:

[{"attributes":{"nodes":["office","tv-area","nerdery","bedroom"]},"id":"status-cluster-size","name":"Bedroom Cluster Size","distributed":false,"state":4},{"attributes":{"quorumReached":false},"id":"status-cluster-leader","name":"Bedroom Cluster Leader","distributed":false,"state":"tv-area"},{"attributes":{},"id":"ble-c53e5f59c30b-tracker","name":"Charger Keys","distributed":true,"state":true},{"attributes":{"distance":1.2,"lastUpdatedAt":"2020-06-10T17:08:32.987Z"},"id":"ble-c53e5f59c30b","name":"Charger Keys Room Presence","distributed":true,"distances":{"Office":{"lastUpdatedAt":"2020-06-10T17:08:32.987Z","distance":1.2,"outOfRange":false},"Bedroom":{"lastUpdatedAt":"2020-06-10T17:08:33.593Z","distance":7.6,"outOfRange":true},"TV_Area":{"lastUpdatedAt":"2020-06-10T16:59:16.414Z","distance":20,"outOfRange":true},"Nerdery":{"lastUpdatedAt":"2020-06-10T17:00:12.145Z","distance":27,"outOfRange":true}},"timeout":5,"measuredValues":{"Office":{"rssi":-60.322669487326465,"measuredPower":-59},"Bedroom":{"rssi":-77.60944172849142,"measuredPower":-59},"TV_Area":{"rssi":-88.16930918966818,"measuredPower":-59},"Nerdery":{"rssi":-91.67955185919278,"measuredPower":-59}},"state":"Office"}]

Expected behavior State changes from BLE devices are sent to MQTT

Environment

Additional context After the Ansible setup was complete I ran all setcap commands and reboot each device. The setup was working previously with an older version of room-assistant. I unfortunately don't recall what version I upgraded from but it was 2.x for sure.

mKeRix commented 4 years ago

I think the issue is that your quorum is not met, which leaves the cluster leader-less. For distributed entities this also means that no state updates are sent to MQTT. In your copy of the entities data I can see you have a total of 4 nodes currently connected to the cluster, but your config has a quorum of 5 (and also 5 peer addresses). For redundancy purposes I would suggest that you set quorum to 3, as this is enough to be a majority. That should also get your entities updated again. After that you can check out which node is not connecting to the cluster and why.

Blink515 commented 4 years ago

Thank you. One of the peers is out of commission at the moment but changing the quorum to 3 did the trick. I guess I don't really have a good understanding of what quorum does, is it even needed in my use case?

mKeRix commented 4 years ago

Not strictly needed, but nice to have nonetheless. It's useful to ensure that there are no conflicts in the entity states when not all nodes are connected. When running 3 or more instances I would recommend to set that value to whatever would be the majority, otherwise it can be left out.