home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.16k stars 30.2k forks source link

MySensors light sensor without unit of measurement #1292

Closed danichispa closed 8 years ago

danichispa commented 8 years ago

Hi all, I'm having an issue in MySensors. A BH1750 sensor reporting fine the lux quantity, but it doesn't get the unit of measurement as "lux". This is the log of the sensor from the homeassistant log.

(Thread-10) [mysensors.mysensors] n:0 c:0 t:3 s:9 p:read: 11-11-0 s=5,c=1,t=37,pt=3,l=2,sg=0:3510

Any idea of how can I get the unit?

Thanks!

MartinHjelmare commented 8 years ago

Hi!

Since the V_LEVEL type (37) can be used for different sensor types, dust, sound, vibration etc, and also lightlevel, I haven't set a predefined unit for that type. What you can do though, is use an additional v_type V_UNIT_PREFIX (43) together with V_LEVEL. The string value that you send for V_UNIT_PREFIX will be used in preference to any unit of measurement, for the sensors you define it for.

Let me know if you need an example.

Edit: This only works with MySensors version 1.5 and later.

danichispa commented 8 years ago

Yes please! :) I suppose this is have to be done on the sensor sketch, right? Thanks in advance!!

MartinHjelmare commented 8 years ago

Yes, this is all done in the arduino sketch:

...
#define CHILD_ID5 5
...
MyMessage msgUnit(CHILD_ID5, V_UNIT_PREFIX);
MyMessage msgLevel(CHILD_ID5, V_LEVEL);

void setup()
{
...
  gw.present(CHILD_ID5, S_LIGHT_LEVEL);
  gw.send(msgUnit.set("lux"));
  gw.send(msgLevel.set("0"));
}
...

I've just broken out the relevant pieces. You have to fill in the gaps (...).

danichispa commented 8 years ago

Thanks @MartinHjelmare !!! Tested and working right now! I close this but left for reference ;)