MisterWil / abodepy

A thin Python wrapper for the Abode alarm API
MIT License
49 stars 17 forks source link

Temperature, Humidity, & Light Sensor #23

Closed ahutchings closed 6 years ago

ahutchings commented 6 years ago
  {
    "id": "ZB:6b1301",
    "type_tag": "device_type.lm",
    "type": "LM",
    "name": "Freezer",
    "area": "1",
    "zone": "17",
    "sort_order": "",
    "is_window": "",
    "bypass": "0",
    "schar_24hr": "0",
    "sresp_24hr": "0",
    "sresp_mode_0": "0",
    "sresp_entry_0": "0",
    "sresp_exit_0": "0",
    "group_name": "Sensors",
    "group_id": "<snip>",
    "default_group_id": "1",
    "sort_id": "1",
    "sresp_mode_1": "0",
    "sresp_entry_1": "0",
    "sresp_exit_1": "0",
    "sresp_mode_2": "0",
    "sresp_entry_2": "0",
    "sresp_exit_2": "0",
    "sresp_mode_3": "0",
    "uuid": "<snip>",
    "sresp_entry_3": "0",
    "sresp_exit_3": "0",
    "sresp_mode_4": "0",
    "sresp_entry_4": "0",
    "sresp_exit_4": "0",
    "version": "LMHT_00.00.03.06TC",
    "origin": "abode",
    "has_subscription": null,
    "control_url": "",
    "deep_link": null,
    "status_color": "#5cb85c",
    "faults": {
      "low_battery": 0,
      "tempered": 0,
      "supervision": 0,
      "out_of_order": 0,
      "no_response": 0
    },
    "status": "-5 \u00b0F",
    "statuses": {
      "temperature": "-5 \u00b0F",
      "temp": "-20.65",
      "lux": "0 lx",
      "humidity": "0 %"
    },
    "status_ex": "",
    "actions": [
      { "label": "High Temperature Alarm", "value": "a=1&z=17&trigger=TSH;" },
      { "label": "Low Temperature Alarm", "value": "a=1&z=17&trigger=TSL;" },
      { "label": "High Humidity Alarm", "value": "a=1&z=17&trigger=HMH;" },
      { "label": "Low Humidity Alarm", "value": "a=1&z=17&trigger=HML;" }
    ],
    "status_icons": [],
    "statusEx": "0",
    "icon": "assets/icons/occupancy-sensor.svg"
  }
shred86 commented 6 years ago

It looks like there's already code for this sensor in both Abodepy and Home Assistant. Does this device show up in HA? It looks like Abodepy might be trying to pull the temp, lux and humidity data from the wrong part of the JSON data. This is the function that is being called in abodepy/sensor.py to get the temp, lux and humidity data:

    def _get_numeric_status(self, key):
        """Extract the numeric value from the statuses object."""
        value = self._get_status(key)

        if value and any(i.isdigit() for i in value):
            return float(re.sub("[^0-9.]", "", value))
        return None

This is the _get_status function:

    def _get_status(self, key):
        return self._json_state.get(CONST.STATUSES_KEY, {}).get(key)

It looks like this needs to actually pull the temp, lux and humidity data from the dictionary in the "statuses" key. Unfortunately I don't have one of these devices to test this out...

MisterWil commented 6 years ago

It looks like this needs to actually pull the temp, lux and humidity data from the dictionary in the "statuses" key.

That's exactly what the _get_status function does. It pulls a key from the statuses dict, and then the _get_numeric_status removes all additional characters other than 0-9 and a decimal point and converts it to a floating point number.

ahutchings commented 6 years ago

For some reason my sensor does not show up in HA at all. Is there any info I can pull from HA to help diagnose the issue?

shred86 commented 6 years ago

Ah, that makes sense. Not sure how I completely missed the CONST.STATUSES_KEY (even though it's in all caps, lol).

@ahutchings Does it show up in the HA logs at all as an unknown device?

I might just order one of these... been looking for a humidity sensor for my house's crawl space.

ahutchings commented 6 years ago

It's currently not showing up at all. However, I think this may be addressed by https://github.com/home-assistant/home-assistant/pull/14313 which is currently in the HA beta release. I will try it out once it reaches the stable channel.

MisterWil commented 6 years ago

Well that's a slightly embarrassing oversight on my part. It would seem that I added all the requisite code to support sensors but never added it as something HASS could initialize. That's what happens when I write code I can't actually test. :(

ahutchings commented 6 years ago

No worries - thanks for getting it to the point where it was a one-liner to fix. :)

Humidity, lux, and temp are all showing up in HA 0.69.0 now, so I'm closing this out.