Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unclear how to get HomeAssistant to discover sensor #79

Closed
seaniedan opened this issue Apr 22, 2021 · 19 comments
Closed

unclear how to get HomeAssistant to discover sensor #79

seaniedan opened this issue Apr 22, 2021 · 19 comments

Comments

@seaniedan
Copy link

I'm trying to set up a Puck.js v2 to use as a doorbell. I'm looking at the notes here and in home assistant.

I've got the raspberry pi runnig the espruino/EspruinoHub to connect to HomeAsisstant:
Apr 22 19:13:04 enviro EspruinoHub[16341]: [MQTT] Connected
and I can see some MQTT messages in HomeAssistant, listening to doorbell/#
Message 41 received on doorbell/presence/xx:xx:xx:xx:73:d9 at 7:22 PM:
1

(that's not my... device by the way.. I don't know what that is)

But I can't get the automatic discovery to work.

My puck is set to do this:

//doorbell advertise bluetooth

NRF.setTxPower(4); // Full Power advertising

//watch doorbell button
var pressCount = 0;
setWatch(function() {
  pressCount++;
  NRF.setAdvertising({
    0xFFFF : pressCount
  });
  digitalPulse(LED3, 1, 1000);
}, BTN, { edge:"falling", repeat:true, debounce:50 });


//advertise 
//temperature and battery level
setInterval(function() {
  NRF.setAdvertising(
    {
    0x1809 : Math.round(E.getTemperature())
    },
    {
    0x180F : E.getBatteryPercentage() 
    }
                    );
}, 5*60*1000);// 5 mins


//setInterval(function() {
//  NRF.setAdvertising({
//    0x180F : E.getBatteryPercentage()
//  },{name: "puckName", interval: 1000});
//}, 30*1000); // 30 seconds

and my config.js is set to to do this:

{
  "// If a device's address is here, it'll be given a human-readable name":0,
  "known_devices" : {
    "xx:xx:xx:xx:1f:8c" : "doorbell"   //(MY PUCK, I THINK)
  },

  "// Set this to true to only publish MQTT messages for known devices":0,
  "only_known_devices": false,

  "// How many seconds to wait for a packet before considering BLE connection":0,
  "// broken and exiting. Higher values are useful with slowly advertising sensors.":0,
  "// Setting a value of 0 disables the exit/restart.":0,
  "ble_timeout": 20,

  "// How many seconds to wait for emitting a presence event, after latest time polled":0,
  "// Default is 60 seconds":0,
  "presence_timeout" : 30,

  "// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0,
  "max_connections" : 4,

  "connection_timeout": 20,

  "// MQTT path for history requests and output. Default is Empty (to disable).":0,
  "//history_path": "/ble/hist/",

  "// We can add our own custom advertising UUIDs here with names to help decode them":0,
  "advertised_services" : {
    "ffff" : {
      "name" : "level"
    }
  },

  "// Make this nonzero to enable the HTTP server on the given port.":0,
  "// See README.md for more info on what it does":0,
  "http_port" : 1888,

  "// Set this to enable the HTTP proxy - it's off by default for safety":0,
  "// since it would be possible to spoof MAC addresses and use your":0,
  "// connection":0,
  "// NOTE: Some Bluetooth adaptors will cause the error: Command Disallowed (0xc)":0,
  "// when trying to connect if http_proxyis enabled.":0,
  "http_proxy" : true,

  "// If there are any addresses here, they are given access to the HTTP proxy":0,
  "http_whitelist" : [
    "xx:xx:xx:xx:1f:8c" //(MY PUCK, I THINK. )
  ],
  "mqtt_host": "mqtt://x.x.x.x", //(REMOTE HOME ASSISTANT ON LAN)
  "mqtt_options": {
    "username": "espruinodoorbell",
    "password": "xxxxxxxxx",
    "clientId": "doorbell"
  },
  "// Define the topic prefix under which the MQTT data will be posted. Defaults to /ble which is not adviced. For new installation, please activate the option below.":0,
  "mqtt_prefix": "/doorbella",

  "// These are the types of MQTT topics that are created":0,
  
  "// Send /ble/advertise/ad:dr:es:ss JSON with raw advertising data, as well as /ble/advertise/ad:dr:es:ss/rssi":0,
  "// This is used by the localhost:1888/ide service to detect devices":0,
  "mqtt_advertise": true,
  "// Send /ble/advertise/ad:dr:es:ss/manufacturer/uuid raw manufacturer data as well as decoded /ble/advertise/ad:dr:es:ss/json_key for json-formatted 0x0590 advertising data":0,
  "mqtt_advertise_manufacturer_data": false,
  "// Send /ble/advertise/ad:dr:es:ss/uuid raw service data":0,
  "mqtt_advertise_service_data": false,
  "// Send /ble/json/ad:dr:es:ss/uuid for decoded service data - REQUIRED FOR HOMEASSISTANT":0,
  "mqtt_format_json": true,
  "// Send /ble/service_name/ad:dr:es:ss for decoded service data":0,
  "mqtt_format_decoded_key_topic": true,

  "// Whether to enable Home Assistant integration":0,
  "homeassistant": true
}

... I'm slightly confused as to how to proceed. Any help gratefully received! I've putting tried all manner of keywords into the 'mqtt_prefix' line, homeassistant/ sensor/ etc. What am I doing wrong?

@gfwilliams
Copy link
Member

gfwilliams commented Apr 23, 2021

Do you see anything in Home assistant like:

image

Personally, I'd just leave the mqtt_prefix at the default /ble for now.

With EspruinoHub working you'd expect to see /ble/presense/de:vi:ce:ad:dr:es events for any bluetooth device in range, so that's probably what you're seeing.

You could check localhost:1888/status and see if your Puck is listed there? It won't be listed if you're still connected to it with the Web IDE, so that might be it?

Maybe you could check and see if you're getting any homeassistant/sensor/... messages on MQTT. If you are then EspruinoHub would appear to be working and the issue would be with HomeAssistant getting the MQTT messages from your local MQTT server?

One issue I do see is that setAdvertising sets all advertising data - so in your Puck code, when the button is pressed you switch to advertising 0xFFFF - but then every 5 minutes that data is reset to temperature + battery. I guess what you probably want is to have a global advData variable:

var advData = {};
//doorbell advertise bluetooth

NRF.setTxPower(4); // Full Power advertising

//watch doorbell button
var pressCount = 0;
setWatch(function() {
  pressCount++;
  advData[0xFFFF] = pressCount;
  NRF.setAdvertising(advData);
  digitalPulse(LED3, 1, 1000);
}, BTN, { edge:"falling", repeat:true, debounce:50 });


//advertise 
//temperature and battery level
setInterval(function() {
   advData[0x1809] = Math.round(E.getTemperature());
   advData[0x180F] = E.getBatteryPercentage();
   NRF.setAdvertising(advData);
}, 5*60*1000);// 5 mins

Also I'm not 100% sure if EspruinoHub currently forwards 0xFFFF to Home Assistant (although it should at least forward temperature). You could try changing 0xFFFF to 0x2a58 (which comes up as 'analog') and see if that helps

@seaniedan
Copy link
Author

Gordon,

I don't see anything in Home assistant like you show (I'm looking on the 'Overview' page).

On the rpi.local:1888/status page, I see the doorbell (a beautiful piece of engineering):
doorbell - Puck.js 1f8c (RSSI -27)
ffff => {"data":161}
f4:fe:fb:7d:ea:f3 - ? (RSSI -95)
[CONNECT] Connections [] IDLE

I suspected I needed to set my homeassistant to look for the mqtt broker on the rpi.local, so I set it in homeassitant's configuarion.yaml:
mqtt:
broker: rpi.local

...restarted everything, it connects, and mqtt server shows:
Message 41 received on doorbell/presence/xx:xx:xx:xx:73:d9 at 3:22 PM:
1
QoS: 0 - Retain: true)

...but no 'discovery'. I guess I can figure out how to code it into my configuration.yaml, something like this was working on a previous version of this repo:


    # Doorbell (Puck.js)
  - platform: mqtt    
    name: "Doorbell Temperature" 
    state_topic: "homeassistant/sensor/doorbell/temperature" 
    unique_id: "sensor.doorbell_temperature"
    unit_of_measurement: "°C" 
    #value_template: "{{ value }}"
  - platform: mqtt    
    name: "Doorbell Battery Level" 
    state_topic: "homeassistant/sensor/doorbell/battery" 
    unique_id: "sensor.doorbell_battery"
    unit_of_measurement: "%" 
    #value_template: "{{ value | int }}"    
  - platform: mqtt    
    name: "Doorbell press" 
    state_topic: "homeassistant/sensor/doorbell/press" 
    unique_id: "sensor.doorbell_press"
    #value_template: "{{ value | int }}"
    #expire_after: 1600    

...but I can't get it to work just now. I thought I'd report to you, in case there's something I'm missing. And also to say, thank you for your suggestions above about the code, and so much for your time, energy and patience while looking into these issues - you're a techno-saint!

@gfwilliams
Copy link
Member

Hmm - that is strange. If EspruinoHub is set up as you say it should really be producing homeassistant/sensor MQTT messages. There should be a whole bunch of other stuff being produced as well... What does the /status say above the list of bluetooth devices?

Mine says something like:

[Config] Config config.json loaded
[HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
[MQTT] Connecting...
[HTTP] Server is listening on http://localhost:1888
[HTTP] www directory found at /home/pi/EspruinoHub/www. Web server at http://localhost:1888
[History] history_path value is empty, thus not providing history.
[MQTT] Connected
[Discover] Re-sending presence status of known devices
[Discover] Noble StateChange: poweredOn
[Discover] Starting scan...
[Discover] Scanning started.
[HTTP] Serving /home/pi/EspruinoHub/www/favicon.ico

Perhaps if you're not getting [MQTT] Connected then it's not actually managing to connect (or stay connected) to the MQTT server?

@seaniedan
Copy link
Author

Hi gordon, I am getting [MQTT] Connected:

[Config] Config config.json loaded
[MQTT] Connecting...
[HTTP] Server is listening on http://localhost:1888
[HTTP] www directory found at /home/sean/EspruinoHub/www. Web server at http://localhost:1888
[History] history_path value is empty, thus not providing history.
[MQTT] Connected
[Discover] Re-sending presence status of known devices
[Discover] Noble StateChange: poweredOn
[HTTPProxy] Bleno State poweredOn
[HTTPProxy] Bleno.startAdvertising Error: Command Disallowed
[Discover] Starting scan...
[Discover] Scanning started.
[HTTP] Serving /home/sean/EspruinoHub/www/index.html
[HTTP] Serving /home/sean/EspruinoHub/www/favicon.ico

Thu Apr 29 2021 14:52:38 GMT+0100 (British Summer Time)

01:9e:c9:12:a9:ee - ? (RSSI -99)
03:c1:4b:2a:72:87 - ? (RSSI -101)
04:21:44:a6:49:bd - JBL Charge 4 (RSSI -96)
14:7d:da:2d:ac:46 - ? (RSSI -97)
14:ec:e7:5d:5e:07 - ? (RSSI -103)
  fd6f => [31,171,33,42,210,51,142,0,6,239,81,203,144,27,245,110,14,154,113,40]
1e:06:9c:27:5b:b5 - ? (RSSI -99)
  fd6f => [233,151,199,18,137,93,129,27,71,201,116,86,224,84,138,122,23,133,74,223]
2a:82:df:c3:c1:a5 - ? (RSSI -96)
2f:31:8e:b3:64:04 - ? (RSSI -95)
36:2f:01:a2:ad:11 - ? (RSSI -96)
49:16:32:1b:1f:c5 - ? (RSSI -98)
4a:ec:e5:0d:5e:83 - ? (RSSI -98)
50:4a:e7:af:87:66 - ? (RSSI -92)
55:1d:bb:83:ec:07 - ? (RSSI -71)
5c:25:8a:6e:70:ad - ? (RSSI -96)
5c:66:0e:d1:76:57 - ? (RSSI -98)
5d:09:d8:c9:c0:ec - ? (RSSI -89)
61:6d:1c:ac:d8:5b - ? (RSSI -97)
6e:01:73:59:7b:b9 - ? (RSSI -92)
6e:78:a2:65:bf:b8 - ? (RSSI -96)
75:7b:09:40:8f:65 - ? (RSSI -98)
76:f5:29:46:85:36 - ? (RSSI -91)
77:b9:9e:1e:5b:52 - ? (RSSI -88)
7f:c7:01:f0:81:ff - ? (RSSI -87)
88:c6:26:f5:e0:6d -  (RSSI -100)
cc:c0:79:d3:ff:5e - EOS200D (RSSI -95)
d0:d0:03:27:92:17 - [TV] Samsung 7 Series (43) (RSSI -96)
doorbell - Puck.js 1f8c (RSSI -28)
  ffff => {"data":162}
[CONNECT] Connections [] IDLE

{"data":162} is the number of times I've pressed the button! :-D

...Homeassistant says it can see the doorbell:

Listen to a topic
 
Listening to
doorbell/#
 
Message 41 received on doorbell/presence/76:ed:7d:18:73:d9 at 2:56 PM:
1
QoS: 0 - Retain: true
Message 40 received on doorbell/presence/1d:87:6b:7b:9d:b3 at 2:56 PM:
1
QoS: 0 - Retain: true
Message 39 received on doorbell/presence/54:7f:6b:36:4d:08 at 2:56 PM:
1

...but it doesn't appear in the 'http://homeassistant:8123/lovelace/default_view' overview page. No new sensors or anything like a doorbell there.

@gfwilliams
Copy link
Member

What is you run:

mosquitto_sub -t "#" -v

And then you press the button? Do you see anything appearing other than just your doorbell/presence/76:ed:7d:18:73:d9 message?

It looks suspiciously like your mqtt prefix is doorbell now, not "mqtt_prefix": "/doorbella",

So is it possible you changed anything else? Like modifying the line "mqtt_format_json": true, ?

@seaniedan
Copy link
Author

sean@enviro:~ $ mosquitto_sub -t "#" -v
/ble/state offline
/ble/presence/office 0
/ble/presence/hall_down 0
/ble/presence/hall_up 0
/ble/presence/ea:17:b5:fb:1f:8c 1
/ble/presence/73:df:0f:b8:9b:17 0
/ble/presence/42:f6:f0:27:cc:3b 0
/ble/presence/59:7d:65:1b:1f:9c 0
/ble/presence/0f:10:25:fb:3b:c4 0
/ble/presence/46:da:9e:44:46:a7 0
/ble/presence/5c:7d:59:12:e1:13 0

...didn't change anything else as far as I remember... looks like mqqtt json is true:

sean@enviro:~ $ cat ~/EspruinoHub/config.json 
{
  "// If a device's address is here, it'll be given a human-readable name":0,
  "known_devices" : {
    "xx:xx:xx:xx:1f:8c" : "doorbell"
  },

  "// Set this to true to only publish MQTT messages for known devices":0,
  "only_known_devices": false,

  "// How many seconds to wait for a packet before considering BLE connection":0,
  "// broken and exiting. Higher values are useful with slowly advertising sensors.":0,
  "// Setting a value of 0 disables the exit/restart.":0,
  "ble_timeout": 20,

  "// How many seconds to wait for emitting a presence event, after latest time polled":0,
  "// Default is 60 seconds":0,
  "presence_timeout" : 30,

  "// Number of simultaneous bluetooth connection the device can handle (PI Zero=4)":0,
  "max_connections" : 4,

  "connection_timeout": 20,

  "// MQTT path for history requests and output. Default is Empty (to disable).":0,
  "//history_path": "/ble/hist/",

  "// We can add our own custom advertising UUIDs here with names to help decode them":0,
  "advertised_services" : {
    "ffff" : {
      "name" : "level"
    }
  },

  "// Make this nonzero to enable the HTTP server on the given port.":0,
  "// See README.md for more info on what it does":0,
  "http_port" : 1888,

  "// Set this to enable the HTTP proxy - it's off by default for safety":0,
  "// since it would be possible to spoof MAC addresses and use your":0,
  "// connection":0,
  "// NOTE: Some Bluetooth adaptors will cause the error: Command Disallowed (0xc)":0,
  "// when trying to connect if http_proxyis enabled.":0,
  "http_proxy" : true,

  "// If there are any addresses here, they are given access to the HTTP proxy":0,
  "http_whitelist" : [
    "xx:xx:xx:xx:1f:8c"
  ],
  "mqtt_host": "mqtt://10.0.1.4",
  "mqtt_options": {
    "username": "xxx",
    "password": "xxx",
    "clientId": "doorbell"
  },
  "// Define the topic prefix under which the MQTT data will be posted. Defaults to /ble which is not adviced. For new installation, please activate the option below.":0,
  "mqtt_prefix": "sensor/doorbell",

  "// These are the types of MQTT topics that are created":0,
  
  "// Send /ble/advertise/ad:dr:es:ss JSON with raw advertising data, as well as /ble/advertise/ad:dr:es:ss/rssi":0,
  "// This is used by the localhost:1888/ide service to detect devices":0,
  "mqtt_advertise": true,
  "// Send /ble/advertise/ad:dr:es:ss/manufacturer/uuid raw manufacturer data as well as decoded /ble/advertise/ad:dr:es:ss/json_key for json-formatted 0x0590 advertising data":0,
  "mqtt_advertise_manufacturer_data": false,
  "// Send /ble/advertise/ad:dr:es:ss/uuid raw service data":0,
  "mqtt_advertise_service_data": false,
  "// Send /ble/json/ad:dr:es:ss/uuid for decoded service data - REQUIRED FOR HOMEASSISTANT":0,
  "mqtt_format_json": true,
  "// Send /ble/service_name/ad:dr:es:ss for decoded service data":0,
  "mqtt_format_decoded_key_topic": true,

  "// Whether to enable Home Assistant integration":0,
  "homeassistant": true
}

@seaniedan
Copy link
Author

..adding to the above, does it matter that I set http proxy to true, and get the error '[HTTPProxy] Bleno.startAdvertising Error: Command Disallowed' - does that mean I am not using http proxy?

@gfwilliams
Copy link
Member

Thanks - that's odd though - now you get /ble/presence/... but I'm pretty sure that would only happen if "mqtt_prefix": "sensor/doorbell", was commented out. Did you definitely restart EspruinoHub after changing things?

I just tried your config file here and it works as I'd expect - creating events like sensor/doorbell/advertise/ca:fc:6f:f3:62:67/rssi - but only if I change "mqtt_host": "mqtt://10.0.1.4" back to the default of localhost.

Is it possible you're just connecting to the wrong MQTT server? The values you see for /ble/presence/... are probably just MQTT messages from some time in the past. When the persistent flag has been set, they get remembered by the server.

does that mean I am not using http proxy?

I think so. You could just disable that for now and see if it helps - I guess it's possible that the error breaks something else?

@seaniedan
Copy link
Author

Set Http proxy to false in ~/EspruinoHub/config.json
sudo systemctl restart EspruinoHub.service && sudo journalctl -f -u EspruinoHub

-- Logs begin at Wed 2021-04-21 13:43:10 BST. --
Apr 29 14:52:19 enviro EspruinoHub[27760]: [HTTP] Serving /home/sean/EspruinoHub/www/favicon.ico
Apr 29 16:11:12 enviro systemd[1]: Stopping EspruinoHub BLE -> MQTT bridge...
Apr 29 16:11:12 enviro systemd[1]: EspruinoHub.service: Main process exited, code=exited, status=1/FAILURE
Apr 29 16:11:12 enviro systemd[1]: EspruinoHub.service: Failed with result 'exit-code'.
Apr 29 16:11:12 enviro systemd[1]: Stopped EspruinoHub BLE -> MQTT bridge.
Apr 29 16:11:12 enviro systemd[1]: Started EspruinoHub BLE -> MQTT bridge.
Apr 29 16:11:12 enviro EspruinoHub[25709]: setterm: $TERM is not defined.
Apr 29 16:11:12 enviro sudo[25718]:     sean : TTY=unknown ; PWD=/home/sean/EspruinoHub ; USER=root ; COMMAND=/sbin/setcap cap_net_raw+eip /usr/bin/node
Apr 29 16:11:12 enviro sudo[25718]: pam_unix(sudo:session): session opened for user root by (uid=0)
Apr 29 16:11:12 enviro sudo[25718]: pam_unix(sudo:session): session closed for user root
Apr 29 16:11:15 enviro EspruinoHub[25709]: Starting without Bleno (GATT Server)
Apr 29 16:11:18 enviro EspruinoHub[25709]: [Config] Config config.json loaded
Apr 29 16:11:18 enviro EspruinoHub[25709]: [HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
Apr 29 16:11:19 enviro EspruinoHub[25709]: [MQTT] Connecting...
Apr 29 16:11:19 enviro EspruinoHub[25709]: [HTTP] Server is listening on http://localhost:1888
Apr 29 16:11:19 enviro EspruinoHub[25709]: [HTTP] www directory found at /home/sean/EspruinoHub/www. Web server at http://localhost:1888
Apr 29 16:11:19 enviro EspruinoHub[25709]: [History] history_path value is empty, thus not providing history.
Apr 29 16:11:19 enviro EspruinoHub[25709]: [Discover] Noble StateChange: poweredOn
Apr 29 16:11:20 enviro EspruinoHub[25709]: [MQTT] Connected
Apr 29 16:11:20 enviro EspruinoHub[25709]: [Discover] Re-sending presence status of known devices
Apr 29 16:11:20 enviro EspruinoHub[25709]: [Discover] Starting scan...
Apr 29 16:11:20 enviro EspruinoHub[25709]: [Discover] Scanning started.

In HomeAssistant, I get:

Message 252 received on sensor/doorbell/advertise/doorbell at 4:15 PM:
{
    "rssi": -27,
    "name": "Puck.js 1f8c",
    "serviceUuids": [
        "6e400001b5a3f393e0a9e50e24dcca9e"
    ]
}

..but no new sensors in the Overview page.

@gfwilliams
Copy link
Member

Ok, so that's new is it?

Earlier I'd mentioned:

You could try changing 0xFFFF to 0x2a58 (which comes up as 'analog') and see if that helps

It looks like that is your problem now. It seems that ffff is now getting decoded by attributes.js as data - and homeassistant.js doesn't understand that so ignores it. I think if you were using the Puck.js code I'd posted above then you should have started seeing at least battery level and temperature appear.

Please can you git pull EspruinoHub now? I changed it so data should get forwarded

@seaniedan
Copy link
Author

Ah yes, I hadn't had a moment to change the code on the puck.

I stash my config.json, git pull, move back my config and restart the espruinohub. All good! On Homeassistant, I now see:

ea:17:b5:fb:1f:8c_data_doorbell
1 minute ago

...and in devices:
Device info

by -
Firmware: EspruinoHub 0.0.1

and in entities:
Entities
ea:17:b5:fb:1f:8c_data_doorbell
Unknown

..so this is good...the sensor has discovered the doorbell! Though I'm not quite sure what to do next, I'd like to be able to read the values (number of clicks, temperature). I'm still unclear why it's unknown, and where those values are in HA.

@seaniedan
Copy link
Author

seaniedan commented Apr 30, 2021

Further experiments: I dropped in the code you posted earlier, and I'm now getting the sensors on HA:
ea:17:b5:fb:1f:8c_data_doorbell
ea:17:b5:fb:1f:8c_temp_doorbell - has a temperature icon - lovely!
No sign of dorbell press count, and the contents of the sensors are 'unknown'. So still unclear how to proceed, but very grateful for your help so far!
image
I suppose my questions at this point are:

  1. Why isn't the 'press count' showing in HA?
  2. Why is the data 'unknown'?
  3. Is it possible to show a nice name like 'Doorbell Temperature' instead of a mac address? I'd entered the name "doorbell" in "known devices" in Espruino hub's json.conf.

@gfwilliams
Copy link
Member

Well, that's more promising!

Why isn't the 'press count' showing in HA? Why is the data 'unknown'?

I think these are related... Please could you do the mosquitto_sub thing again and see if you get any update messages for the temperature/press count that match the sensor? So for instance I get:

homeassistant/sensor/eb44c1712e89/1809_temp/config {"unit_of_measurement":"°C","device_class":"temperature","state_topic":"/ble/json/eb:44:c1:71:2e:89/1809","value_template":"{{ value_json.temp}}","json_attributes_topic":"/ble/json/eb:44:c1:71:2e:89/1809","name":"eb:44:c1:71:2e:89_temp","unique_id":"eb:44:c1:71:2e:89_1809_temp","device":{"identifiers":["eb:44:c1:71:2e:89"],"name":"Espruino 2e89","sw_version":"EspruinoHub 0.0.1","model":"-","manufacturer":"-"},"availability":[{"topic":"/ble/presence/eb:44:c1:71:2e:89","payload_available":"1","payload_not_available":"0"},{"topic":"/ble/state"}]}

and

/ble/json/eb:44:c1:71:2e:89/1809 {"temp":16.75,"rssi":-71}

Which matches what's in state_topic of the JSON above.

I guess it's possible that your modified prefix of "mqtt_prefix": "sensor/doorbell", is breaking things somehow...

Is it possible to show a nice name like 'Doorbell Temperature' instead of a mac address? I'd entered the name "doorbell" in "known devices" in Espruino hub's json.conf.

Interestingly you're getting ea:17:b5:fb:1f:8c_temp_doorbell so I guess the name doorbell is being picked up from known_devices, but yes, ideally the name would actually just be doorbell_temp. That'd require a change in homeassistant.js.

Having said that, I would imagine you can rename them in Home Assistant?

@seaniedan
Copy link
Author

sean@enviro:~ $ mosquitto_sub -t "#" -v
/ble/state offline
/ble/presence/office 0
/ble/presence/hall_down 0
/ble/presence/hall_up 0
/ble/presence/ea:17:b5:fb:1f:8c 1
/ble/presence/73:df:0f:b8:9b:17 0
/ble/presence/42:f6:f0:27:cc:3b 0
/ble/presence/59:7d:65:1b:1f:9c 0
/ble/presence/0f:10:25:fb:3b:c4 0
/ble/presence/46:da:9e:44:46:a7 0
/ble/presence/5c:7d:59:12:e1:13 0
/ble/presence/36:52:1e:ac:84:94 0
/ble/presence/3e:05:9a:06:dd:0b 0

...etc, no mention of doorbells. (I left it for 5 mins..!)

" ideally the name would actually just be doorbell_temp. That'd require a change in homeassistant.js.":

I use metrics2mqtt which gives labels such as "MyHostName Virtual Memory" and the measurements and units. It doesn't require any additional config in homeassistant! I highly recommend it.

@gfwilliams
Copy link
Member

Ahh - actually, you need mosquitto_sub -t "#" -v -h 10.0.1.14 I guess as you're not using your local MQTT server?

@seaniedan
Copy link
Author

mosquitto_sub -t "#" -v -h MyHomeassistant -u MyUsername -P MyExceptionalPassword
gives

homeassistant/sensor/ea17b5fb1f8c/ffff_data/config {"state_topic":"doorbell/json/ea:17:b5:fb:1f:8c/ffff","value_template":"{{ value_json.data}}","json_attributes_topic":"doorbell/json/ea:17:b5:fb:1f:8c/ffff","name":"ea:17:b5:fb:1f:8c_data_doorbell","unique_id":"ea:17:b5:fb:1f:8c_ffff_data_doorbell","device":{"identifiers":["ea:17:b5:fb:1f:8c_doorbell"],"name":"Puck.js 1f8c","sw_version":"EspruinoHub 0.0.1","model":"-","manufacturer":"-"},"availability":[{"topic":"doorbell/presence/ea:17:b5:fb:1f:8c","payload_available":"1","payload_not_available":"0"},{"topic":"doorbell/state"}]}
homeassistant/sensor/ea17b5fb1f8c/1809_temp/config {"unit_of_measurement":"°C","device_class":"temperature","state_topic":"doorbell/json/ea:17:b5:fb:1f:8c/1809","value_template":"{{ value_json.temp}}","json_attributes_topic":"doorbell/json/ea:17:b5:fb:1f:8c/1809","name":"ea:17:b5:fb:1f:8c_temp_doorbell","unique_id":"ea:17:b5:fb:1f:8c_1809_temp_doorbell","device":{"identifiers":["ea:17:b5:fb:1f:8c_doorbell"],"name":"Puck.js 1f8c","sw_version":"EspruinoHub 0.0.1","model":"-","manufacturer":"-"},"availability":[{"topic":"doorbell/presence/ea:17:b5:fb:1f:8c","payload_available":"1","payload_not_available":"0"},{"topic":"doorbell/state"}]}
doorbell/state online
doorbell/presence/doorbell 1
doorbell/presence/25:d4:de:5d:79:95 1
...
doorbell/advertise/25:d4:de:5d:79:95 {"rssi":-73,"serviceUuids":["fd6f"]}
doorbell/advertise/41:e1:49:1f:37:5b/rssi -89
doorbell/advertise/20:3c:f6:98:55:e7 {"rssi":-83,"serviceUuids":[]}
doorbell/advertise/20:3c:f6:98:55:e7/rssi -83
doorbell/advertise/doorbell {"rssi":-27,"name":"Puck.js 1f8c","serviceUuids":["6e400001b5a3f393e0a9e50e24dcca9e"]}

Espruino status page shows:

[Config] Config config.json loaded
[HTTPProxy] config.http_proxy=false, not enabling Bleno/Proxy
[MQTT] Connecting...
[HTTP] Server is listening on http://localhost:1888
[HTTP] www directory found at /home/sean/EspruinoHub/www. Web server at http://localhost:1888
[History] history_path value is empty, thus not providing history.
[Discover] Noble StateChange: poweredOn
[MQTT] Connected
[Discover] Re-sending presence status of known devices
[Discover] Starting scan...
[Discover] Scanning started.
[HTTP] Serving /home/sean/EspruinoHub/www/favicon.ico

Tue May 04 2021 17:14:21 GMT+0100 (British Summer Time)

04:19:b9:ee:df:7e - ? (RSSI -96)
17:75:51:8b:27:96 - ? (RSSI -76)
  fd6f => [39,50,185,154,215,81,118,96,17,173,239,70,191,41,124,67,101,248,53,233]
20:3c:f6:98:55:e7 - ? (RSSI -94)
...
c0:00:00:00:00:05 - ? (RSSI -93)
doorbell - Puck.js 1f8c (RSSI -27)
  1809 => {"temp":19}
  ffff => {"data":5}
f4:fe:fb:7d:ea:f3 - ? (RSSI -96)
[CONNECT] Connections [] IDLE

HomeAssistant shows:
ea:17:b5:fb:1f:8c_data_doorbell Unknown
ea:17:b5:fb:1f:8c_temp_doorbell Unknown

@gfwilliams
Copy link
Member

Ok, that seems a lot more reasonable! Although it seems that maybe the doorbell Puck wasn't running any code when you ran the command?

Please can you try removing the "xx:xx:xx:xx:1f:8c" : "doorbell" line from config.json? Just a hunch, but I wonder whether the homeassistant code gets confused - it's expecting an MQTT topic doorbell/json/ea:17:b5:fb:1f:8c/ffff but actually doorbell/json/doorbell/ffffis what gets sent...

@seaniedan
Copy link
Author

seaniedan commented May 5, 2021

You nailed it! Removing the "xx:xx:xx:xx:1f:8c" : "doorbell" line from config.json helped:
image
I think that solves questions 1 and 2 from above. For point 3, to get a nicer name in HA, I clicked on the discovered sensor, clicked the cog in the top right, and typed a new name.

THANK YOU GORDON! :-D

@gfwilliams
Copy link
Member

Great - thanks for letting me know! I just filed an issue to fix the underlying problem properly: #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants