NorthernMan54 / homebridge-tasmota

Plugin for Tasmota devices leveraging Home Assistant auto discovery
Apache License 2.0
35 stars 9 forks source link

Add support for BH1750 #6

Closed StumbleNOLA closed 4 years ago

StumbleNOLA commented 4 years ago

*Is your feature request related to a problem? Please describe: A BH1750 Lux sensor is unable to import lux data to HomeKit

Describe the solution you'd like: Some way to use the BH1750 in HomeKit

Describe alternatives you've considered: I considered installing https://www.npmjs.com/package/homebridge-mqtt-lux-tasmota which is specifically for the BH1750, or another lux sensor plugin, but I would much prefer to keep the number of MQTT plugins as low as possible.

Additional context: When imported thru the plugin the sensor is displayed in HomeKt, but under the device panel there is "This accessory is not currently supported by the Home app." I also looked for it in the Eve app, and so far as I can see it doesn't even appear as a tile.

It does show up as a tile in Home+ 4, however there is no data there, and no light sensor.

NorthernMan54 commented 4 years ago

Can you share the config from Tasmota so I can set one up in my environment

StumbleNOLA commented 4 years ago

I followed the setup here. https://tasmota.github.io/docs/BH1750/

Is there a specific setup page you are looking for? I am away from home for the weekend but can post it on Tuesday.

StumbleNOLA commented 4 years ago

@NorthernMan54

I am not sure which config you are looking for if its a specific file.

Its set up as generic, D6 - I2C SDA D7 - I2C SCL

MQTT Parameters Topic - tasmota_%06X Full Topic - %prefix%/%topic%/

If you can let me know what you are looking for I can get it up in a few minutes.

NorthernMan54 commented 4 years ago

This is good, I was looking for the Tasmota config which is included in the link.

Just need some time to give it a try and see what’s up.

So far I have wired temperature and humdity

StumbleNOLA commented 4 years ago

Sounds good, just let me know if you need anything.

BTW I have confirmed the plugin with DHT-11 sensors, including multiple DHT11's on the same board for the readme.

NorthernMan54 commented 4 years ago

I thought I would have been able to configure one of my devices to emulate being a BH1750, but it doesn't work. I looks like Tasmota is also auto detecting the connected device so I can not emulate one. So I will need a copy of the homeassistant discovery messages from the device. If you enable the DEBUG option in the plugin config, set "setoption19 1" on the device, and restart homebridge it will log the discovery messages. In the log file the discovery messages look like this and their should be a couple.

  Tasmota:platform Discovered -> Sensors BME280 Temperature {
  name: 'Sensors BME280 Temperature',
  stat_t: '~SENSOR',
  avty_t: '~LWT',
  frc_upd: true,
  pl_avail: 'Online',
  pl_not_avail: 'Offline',
  uniq_id: '869815_BME280_Temperature',
  device: { identifiers: [ '869815' ], connections: [ [Array] ] },
  '~': 'tasmota-6165/tele/',
  unit_of_meas: '°C',
  val_tpl: "{{value_json['BME280'].Temperature}}",
  dev_cla: 'temperature',
  tasmotaType: 'sensor'
}

If you could post these here, I should be able to set it up pretty quickly.

StumbleNOLA commented 4 years ago

Here you go.

} [9/9/2020, 21:33:09] [Tasmota] Restoring existing service from cache: Sofa Table status 2020-09-10T02:33:09.745Z Tasmota:platform Discovered -> Light Temp Humid BH1750 Illuminance

{
  name: 'Light Temp Humid BH1750 Illuminance',
  stat_t: 'tele/MultiSens_1/SENSOR',
  avty_t: 'tele/MultiSens_1/LWT',
  pl_avail: 'Online',
  pl_not_avail: 'Offline',
  uniq_id: '0AF65D_BH1750_Illuminance',
  dev: { ids: [ '0AF65D' ] },
  unit_of_meas: 'LX',
  dev_cla: 'illuminance',
  frc_upd: true,
  val_tpl: "{{value_json['BH1750']['Illuminance']}}",
  tasmotaType: 'sensor'
}

[9/9/2020, 21:33:09] [Tasmota] Restoring existing service from cache: Light Temp Humid BH1750 Illuminance 2020-09-10T02:33:09.749Z Tasmota:platform Discovered -> Light Temp Humid status

{
  name: 'Light Temp Humid status',
  stat_t: 'tele/MultiSens_1/HASS_STATE',
  avty_t: 'tele/MultiSens_1/LWT',
  pl_avail: 'Online',
  pl_not_avail: 'Offline',
  json_attr_t: 'tele/MultiSens_1/HASS_STATE',
  unit_of_meas: '%',
  val_tpl: "{{value_json['RSSI']}}",
  ic: 'mdi:information-outline',
  uniq_id: '0AF65D_status',
  dev: {
    ids: [ '0AF65D' ],
    name: 'Light Temp Humid',
    mdl: 'Generic',
    sw: '8.4.0(sensors)',
    mf: 'Tasmota'
  },
  tasmotaType: 'sensor'
}
NorthernMan54 commented 4 years ago

Any idea what the range of values are ? The HomeKit spec says this

https://developers.homebridge.io/#/characteristic/CurrentAmbientLightLevel

NorthernMan54 commented 4 years ago

Tks, if you update to the latest version they may work. I can't test this so fingers crossed that it works.

StumbleNOLA commented 4 years ago

Possible or realistic?

Sitting is a somewhat dim room I am getting a reading of 39 lux, down to 0 if I put my finger over the sensor. Putting the sensor about 20mm away from a 60W LED desk lamp bulb I get about 20,000lux. I think a bright sunny day is around 10,000.

StumbleNOLA commented 4 years ago

I am updating now, I'll let you know in a few.

NorthernMan54 commented 4 years ago

Tks values look valid based on the spec

On Sep 9, 2020, at 10:44 PM, StumbleNOLA notifications@github.com wrote:

Possible or realistic?

Sitting is a somewhat dim room I am getting a reading of 39 lux, down to 0 if I put my finger over the sensor. Putting the sensor away 20mm from a 60W LED desk lamp bulb I get about 20,000lux. I think a bright sunny day is around 10,000.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NorthernMan54/homebridge-tasmota/issues/6#issuecomment-689940747, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXEFGC53OT3J5Y3UUN2DRTSFA4RBANCNFSM4QZLIIMA.

NorthernMan54 commented 4 years ago

Made a small oops, v0.0.23 should work

StumbleNOLA commented 4 years ago

Its picking up the sensor, but reading 122 degrees F. The WebUI for Tasmota reads ~50lux

NorthernMan54 commented 4 years ago

In v0.0.22 I created it as a temperature sensor, in v0.0.23 it it the light sensor

On Sep 9, 2020, at 10:52 PM, StumbleNOLA notifications@github.com wrote:

Its picking up the sensor, but reading 122 degrees F. The WebUI for Tasmota reads ~50lux

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NorthernMan54/homebridge-tasmota/issues/6#issuecomment-689943411, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXEFGC3YMXZDBRPPNWU37DSFA5PNANCNFSM4QZLIIMA.

StumbleNOLA commented 4 years ago

Could it just need to populate then?

The Homebridge logs now include: [9/9/2020, 21:51:55] [Tasmota] statusUpdate Light Temp Humid BH1750 Illuminance to 50 [9/9/2020, 21:51:55] [Tasmota] statusUpdate Light Temp Humid BME280 Temperature to 23.6 [9/9/2020, 21:51:55] [Tasmota] statusUpdate Light Temp Humid BME280 Humidity to 41.6 [9/9/2020, 21:52:37] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 24.9 [9/9/2020, 21:52:37] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 45

So its getting to there correctly, its just still interpreting it as a temp.

But since I updated to .23 about 30 seconds ago...

NorthernMan54 commented 4 years ago

Maybe

Or delete it out of homebridge and have it be discovered again?

On Sep 9, 2020, at 10:56 PM, StumbleNOLA notifications@github.com wrote:

Could it just need to populate then?

The Homebridge logs now include: [9/9/2020, 21:51:55] [Tasmota] statusUpdate Light Temp Humid BH1750 Illuminance to 50 [9/9/2020, 21:51:55] [Tasmota] statusUpdate Light Temp Humid BME280 Temperature to 23.6 [9/9/2020, 21:51:55] [Tasmota] statusUpdate Light Temp Humid BME280 Humidity to 41.6 [9/9/2020, 21:52:37] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 24.9 [9/9/2020, 21:52:37] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 45

So its getting to there correctly, its just still interpreting it as a temp.

But since I updated to .23 about 30 seconds ago...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NorthernMan54/homebridge-tasmota/issues/6#issuecomment-689944523, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXEFGFMB5YAC6322QGGOZDSFA543ANCNFSM4QZLIIMA.

StumbleNOLA commented 4 years ago

Ok, I deleted it from the TasUI devices screen, reloaded homebridge, and the sensor popped back without re-adding it in TasUI.

The data looks the same. Including that it shows the sensor type as a temperature. It seems to be converting 50Lux to Fahrenheit correctly though...

Is there another way to delete it from homebridge?

Screen Shot 2020-09-09 at 10 01 37 PM
NorthernMan54 commented 4 years ago

A little bit lower on the screen, Current Ambient Light Level 49

On Sep 9, 2020, at 11:03 PM, StumbleNOLA notifications@github.com wrote:

Ok, I deleted it from the TasUI devices screen, reloaded homebridge, and the sensor popped back without re-adding it in TasUI.

The data looks the same. Including that it shows the sensor type as a temperature. It seems to be converting 50Lux to Fahrenheit correctly though...

https://user-images.githubusercontent.com/44331352/92676904-2678b200-f2e8-11ea-93fa-8bd20e7576c7.png — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NorthernMan54/homebridge-tasmota/issues/6#issuecomment-689946957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEXEFGBNBMHCLDMLHECFJPTSFA6Y7ANCNFSM4QZLIIMA.

StumbleNOLA commented 4 years ago

Ya, its showing up there, but not as a sensor in HomeKit. It populates the accessory tabs with:

Screen Shot 2020-09-09 at 10 08 18 PM

And it show the following in HomeKit.

Screen Shot 2020-09-09 at 10 09 14 PM

Note that 122F is correct if the input (50Lux) is being treated as a temperature and converted from C to F.

NorthernMan54 commented 4 years ago

Looks like my oops is stuck inside homebridge. You would need to delete it from homebridge.

You can trick it by changing the cleanup setting to 0.125, unplug the device, restart homebridge. And in about 10-15 minutes it will be deleted. Then put the cleanup setting back, restart homebridge and it should be fine

StumbleNOLA commented 4 years ago

I am letting it clock, but I am pretty sure its been over 15 minutes since I deleted it from TasUI, and restarting Homebridge. But the trio shill show up in Accessories when I restart Homebridge.

StumbleNOLA commented 4 years ago

NM. If you go to Homebridge and click on the three dots. Then "Homebridge Settings" you can directly remove accessories from the cash file.

StumbleNOLA commented 4 years ago

Ok, it seems the sensor is working correctly generally, and Lux is showing up properly in the Homebridge UI.

In HomeKit however all my Tasmota sensors are intermittently showing 'No Response.' If I separate them out as separate tiles they seem to work correctly. Except for the Lux sensor which is permanently "No Response."

If I go to the Accessories tab, under each sensor it shows "on = False" but the log indicates the sensors are updating from time to time.

Edit: I pulled these logs indicating the sensors are updating every 5 minutes or so. [9/10/2020, 00:29:48] [Tasmota] statusUpdate Light Temp Humid BH1750 Illuminance to 33 [9/10/2020, 00:29:48] [Tasmota] statusUpdate Light Temp Humid BME280 Temperature to 23.3 [9/10/2020, 00:29:48] [Tasmota] statusUpdate Light Temp Humid BME280 Humidity to 44.1 [9/10/2020, 00:34:48] [Tasmota] statusUpdate Light Temp Humid BH1750 Illuminance to 32 [9/10/2020, 00:34:48] [Tasmota] statusUpdate Light Temp Humid BME280 Temperature to 23.5 [9/10/2020, 00:34:48] [Tasmota] statusUpdate Light Temp Humid BME280 Humidity to 43.9 [9/10/2020, 00:34:49] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 24.6 [9/10/2020, 00:39:48] [Tasmota] statusUpdate Light Temp Humid BME280 Temperature to 23.6 [9/10/2020, 00:39:48] [Tasmota] statusUpdate Light Temp Humid BME280 Humidity to 43.9 [9/10/2020, 00:39:49] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 24.7 [9/10/2020, 00:39:49] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 48

It makes me wonder if the delay in the logging from the other pull request could be kicking the sensors off line somehow.

NorthernMan54 commented 4 years ago

I found a coding issue around "Not Responding" and sensors which I have resolved. Please update and try again.

I did spend some time doing testing of the Not Responding and auto removal logic, and did find an unusual behaviour, if you unplug a device, it will go "Not Responding" within approx 5 minutes, then at the "Cleanup" interval it will be removed from HomeKIt. But when you restart the plugin it gets added back, and the cycle begins again ;-(

Going to raise this as a separate issue

StumbleNOLA commented 4 years ago

For whatever reason all the sensors (DHT11's as well) are still showing up as "No Response" when I click on them they populate but fall back to "No Response" if I close the app, or switch to another app. This is not the same behavior as in the Home app on my Mac, which will pull up the data while the sensor is open, but immediately defaults to "No Response" when you close the sensor panel.

The Lux sensor IS getting the correct lux readings in the Accessories tab of Homebridge. But is not getting to the sensor in the HomeKit app (Or Eve, or Home+4 apps).

Screen Shot 2020-09-10 at 1 23 43 PM
NorthernMan54 commented 4 years ago

No response can also be triggered by bad data being shared with HomeKit.

I’m wondering if the multi sensor config is causing the issue. I need to take one of my devices and attach a second sensor to see the impact.

When I test with a single BME280 it just works.

On Sep 10, 2020, at 2:26 PM, StumbleNOLA notifications@github.com wrote:

 For whatever reason all the sensors (DHT11's as well) are still showing up as "No Response" when I click on them they populate but fall back to "No Response" if I close the app, or switch to another app. This is not the same behavior as in the Home app on my Mac, which will pull up the data while the sensor is open, but immediately defaults to "No Response" when you close the sensor panel.

The Lux sensor IS getting the correct lux readings in the Accessories tab of Homebridge. But is not getting to the sensor in the HomeKit app (Or Eve, or Home+4 apps).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

StumbleNOLA commented 4 years ago

Weird,

After the last update when I go to TasUI, and click on devices, the screen goes blank. I can discover devices, but not interact with them (I can't even see them).

StumbleNOLA commented 4 years ago

No response can also be triggered by bad data being shared with HomeKit. I’m wondering if the multi sensor config is causing the issue. I need to take one of my devices and attach a second sensor to see the impact. When I test with a single BME280 it just works.

I pulled the other sensor off the board, so the only thing attached is the LUX sensor. The behavior is the same, it is reported properly into Homebridge, but in the iPhone app the sensor just reportes "No Response."

The other Tasmota sensors I have on the network, just a DHT11 and the Esp8266 NUC also are reporting "No Response" but if I click on them in the HomeKit app properly populate the data.

NorthernMan54 commented 4 years ago

I'm wondering if I need to purchase a BH1570 sensor to recreate your setup.

I have been testing with 2 DHT22 and a BME280, and found an minor issue around device discovery and device boots

IMG_5343

IMG_5341

IMG_5344

In MQTT Explorer I can see some phantom sensor config's. The module I'm playing with is "homeassistant/sensor/5673B2..." And the AM2301 entry without the - after is phantom. This was created when I was running with a single DHT22, and when I added a second two new entries were created with the -. And in HK I have a phantom Temperature and Humidity sensor that maps to it. They are stuck at 0

I need to delete the two phantom entries in MQTT Explorer and delete the accessory in homebridge and recreate it to fix.

Second thing I found was that rebooting the device caused additional sensor data updates in the plugin itself. Need to fix this.

Also the more recent version has additional logging around "Not Responding" and should now log a message when it is triggered.

Screen Shot 2020-09-10 at 5 07 51 PM

NorthernMan54 commented 4 years ago

Weird,

After the last update when I go to TasUI, and click on devices, the screen goes blank. I can discover devices, but not interact with them (I can't even see them).

Keep in mind that tasui is not mine, but a very useful utility to mange your devices. It does not change the plugin behaviour or impact discovery etc. I use it to find my devices web site after the initial setup.

I have seen the same issue and restarting the browser resolved it.

StumbleNOLA commented 4 years ago

So just to try...

I reinstalled Tasmota. Took everything off the Lux board except the one sensor deleted the plugin cleared the cash from Homebridge of the lux plugin Deleted the sensor data from MQTT Explorer of everything

Then loaded everything back up.

No change. The data still properly populates to Homebridge, but not to HomeKit.

[9/10/2020, 20:59:00] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 25.5 [9/10/2020, 20:59:00] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 43 [9/10/2020, 21:00:13] [Tasmota] statusUpdate Light Temp Humid BH1750 Illuminance to 30 [9/10/2020, 21:04:00] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 25.4 [9/10/2020, 21:04:00] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 45 [9/10/2020, 21:05:13] [Tasmota] statusUpdate Light Temp Humid BH1750 Illuminance to 31 [9/10/2020, 21:09:00] [Tasmota] statusUpdate Sofa Table DHT11 Temperature to 25.5 [9/10/2020, 21:09:00] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 47 [9/10/2020, 21:14:00] [Tasmota] statusUpdate Sofa Table DHT11 Humidity to 46

Screen Shot 2020-09-10 at 9 18 49 PM Screen Shot 2020-09-10 at 9 19 05 PM
NorthernMan54 commented 4 years ago

I’m going to purchase the same sensor and create the same device in my setup to see why this isn’t working, give me a couple of days.

StumbleNOLA commented 4 years ago

Sure. Thanks for taking that step.

NorthernMan54 commented 4 years ago

Can you share what sensors you would have connected? I'm going to create the same device here. Also the version of Tasmota.

StumbleNOLA commented 4 years ago

I am hoping to use a BH1750 (Lux Sensor), and a BME280 on the same 8266 NodeMCU. Specifically https://www.amazon.com/gp/product/B00M0F29OS/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&psc=1 and https://www.amazon.com/gp/product/B07WZZTX41/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1

The devices are currently running Tasmota-Sensor 8.4.0, though I noticed they just upgraded to 8.5. Specifically the release tasmota-sensor.bin from http://ota.tasmota.com/tasmota/release/

NorthernMan54 commented 4 years ago

I think I have nailed the issue, found that the sensor was sending a minimum value of 0, while within HomeKit the minimum value is 0.0001.

To find this issue and to test the limits of a sensor device created a franken sensor with 2 DHT22, 2 BME280 and a BH1750

IMG_5365

In Tasmota it looks like this

IMG_5367

In HomeKit is looks like this

IMG_5368

And when I was able to recreate the error

IMG_5369

I have published the fix for this, so if you update to the latest version it should work okay now. I'm going to leave my sensor running for the next few days to see if their are other issues.

StumbleNOLA commented 4 years ago

I updated a few minutes ago, and it appears to be working perfectly.

Thank you very much.

StumbleNOLA commented 4 years ago

Well, the sensor does appear to be working well, but further testing indicated an issue. The refresh rate in the lux sensor is averaging about once every 3 minutes. Is there any way to increase the refresh rate?

NorthernMan54 commented 4 years ago

Going to close this as the original issue has been resolved, and create another to discuss