Closed skullydazed closed 3 years ago
I coded the plugin directly against how Tasmota manages Mqtt autodiscovery, and never looked at ESPHome devices so this is expected. I did fix the issue that triggered the exception, but can not confirm if it works without an ESPhome device but theoretical it should with some minor tweaks. So getting this to work is likely to be a bit of wack a mole thru what ever issues do surface. The detail you provided was extremely helpful in resolving this.
For the fix I coded this against the current beta branch, so to install please use add the @beta tag to the install command ie
npm install -g homebridge-tasmota@beta
I'm happy to whack as long as you're happy to provide hammers.
I think maybe something didn't get published, I'm still picking up 0.0.80:
redwood:/var/lib/homebridge:0$ sudo npm install -g homebridge-tasmota@beta
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/homebridge-tasmota/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ homebridge-tasmota@0.0.80
added 126 packages from 88 contributors in 10.193s
Minor publishing issue, it should now be v0.0.83
This is looking better. Discovery seems to work:
2021-02-02T03:11:13.324Z Tasmota:platform Discovered -> homeassistant/binary_sensor/office_sensor/office_motion/config O
ffice Motion {
dev_cla: 'motion',
name: 'Office Motion',
stat_t: 'office_sensor/binary_sensor/office_motion/state',
avty_t: 'office_sensor/status',
uniq_id: 'ESPbinary_sensoroffice_motion',
dev: {
ids: '10521c0287d9',
name: 'office_sensor',
sw: 'esphome v1.15.3 Feb 1 2021, 13:12:37',
mdl: 'PLATFORMIO_D1_MINI',
mf: 'espressif'
},
tasmotaType: 'binary_sensor'
}
[2/1/2021, 7:11:13 PM] [Tasmota] Adding new accessory: Office Motion
2021-02-02T03:11:13.328Z Tasmota:Service fakegatoService exists Office Motion
2021-02-02T03:11:13.328Z Tasmota:mqtt sendMessage office_sensor/binary_sensor/office_motion/teleperiod 300
2021-02-02T03:11:13.329Z Tasmota:platform discovery devices - this.api.registerPlatformAccessories
HAP Warning: Characteristic 000000E3-0000-1000-8000-0026BB765291 not in required or optional characteristics for service
00000085-0000-1000-8000-0026BB765291. Adding anyway.
2021-02-02T03:11:13.342Z Tasmota:platform Discovered -> homeassistant/binary_sensor/wifikit32/wifikit32_motion/config Wi
fikit32 Motion {
dev_cla: 'motion',
name: 'Wifikit32 Motion',
stat_t: 'wifikit32/binary_sensor/wifikit32_motion/state',
avty_t: 'wifikit32/status',
uniq_id: 'ESPbinary_sensorwifikit32_motion',
dev: {
ids: '7c9ebdfc04c8',
name: 'wifikit32',
sw: 'esphome v1.15.3 Jan 26 2021, 20:58:27',
mdl: 'Heltec WiFi Kit 32',
mf: 'espressif'
},
tasmotaType: 'binary_sensor'
}
However it doesn't seem to like ON and OFF as state vars:
2021-02-02T03:11:14.064Z Tasmota:binarySensor MQTT office_sensor/binary_sensor/office_motion/state ON
[2/1/2021, 7:11:14 PM] [Tasmota] ERROR: Message Parse Error office_sensor/binary_sensor/office_motion/state ON
[2/1/2021, 7:11:14 PM] [Tasmota] Marking accessory 'Office Motion' to online
Now this is where is gets tricky, as the Tasmota devices are using JSON objects like this for status
tasmota_562CC4/stat/SWITCH1
{"STATE":"ON"}
And the plugin is parsing the config object, and using the 'value_template' and 'stat_t' ( state_topic ) to determine how to parse the status. I borrowed portions of the parser from home assistant, but only implemented the JSON parser as Tasmota devices are doing JSON.
homeassistant/binary_sensor/562CC4_SW_1/config
{"name":"Dining Room Light Sensor Switch1",
"stat_t":"~stat/SWITCH1",
"avty_t":"~tele/LWT",
"pl_avail":"Online",
"pl_not_avail":"Offline",
"uniq_id":"562CC4_SW_1","device":{"identifiers":["562CC4"],"connections":[["mac","CC:50:E3:56:2C:C4"]]},
"~":"tasmota_562CC4/",
"value_template":"{{value_json.STATE}}",
"frc_upd":true,
"pl_on":"ON",
"pl_off":"OFF"}
Does ESP home a similar pattern ?
PS This is from my combo sensor ( BME280, BH1750 LUX and AM312 PIR Motion )
I've seen that pattern used for other devices (in fact I use it for a couple of my own projects that do homeassistant auto discovery) but esphome devices use simple strings for the state. When value_template
, pl_on
, and pl_off
are not provided (as they are not in this case) this is what is assumed.
If there is an ESPHome setting to send the state in a JSON message, then to getting it work will likely mean just tweaking the discovery message with an override to add the missing discovery elements.
After iterating on this over discord things are looking good. With 0.0.98 and the following minor patch all my devices are working great:
redwood:/usr/lib/node_modules/homebridge-tasmota/dist:148$ diff -u tasmotaSwitchService.js.dist tasmotaSwitchService.js
--- tasmotaSwitchService.js.dist 2021-02-04 11:54:48.270118900 -0800
+++ tasmotaSwitchService.js 2021-02-04 12:01:59.835522799 -0800
@@ -45,9 +45,6 @@
debug('MQTT', topic, message.toString());
try {
this.accessory.context.timeout = this.platform.autoCleanup(this.accessory);
- const interim = {
- value_json: JSON.parse(message.toString()),
- };
let value = message.toString();
if (this.accessory.context.device[this.uniq_id].val_tpl) {
value = this.parseValue(this.accessory.context.device[this.uniq_id].val_tpl, {
@@ -56,6 +53,9 @@
}
value = (value === this.accessory.context.device[this.uniq_id].pl_on ? true : false);
if (typeof this.accessory.context.device[this.uniq_id].pl_on === 'boolean') {
+ const interim = {
+ value_json: JSON.parse(message.toString()),
+ };
value = TasmotaService_1.isTrue(this.parseValue(this.accessory.context.device[this.uniq_id].val_tpl, interim));
}
if (this.characteristic.value !== value) {
This is should now be 100% functional
Describe The Bug:
I have an esp8266 running esphome with some sensors attached. None of the sensors work and all throw the same error. Focusing only on 1 sensor for ease of debugging, but this applies to every device I've tried to use, including the esp32, tuya plugs, and my zwave2mqtt devices which also publish homeassistant autoconfig entries.
To Reproduce:
homeassistant/binary_sensor/office_sensor/office_motion/config
:{"device_class":"motion","name":"Office Motion","state_topic":"office_sensor/binary_sensor/office_motion/state","availability_topic":"office_sensor/status","unique_id":"ESPbinary_sensoroffice_motion","device":{"identifiers":"10521c0287d9","name":"office_sensor","sw_version":"esphome v1.15.3 Jan 26 2021, 15:07:02","model":"PLATFORMIO_D1_MINI","manufacturer":"espressif"}}
Expected behavior:
Discovered devices should show up in Home.app, but don't.
Logs:
ESPHome Device Config: