Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

added tholddark, please add to CC setup? #111

Closed
Mariusthvdb opened this issue Jan 28, 2019 · 5 comments
Closed

added tholddark, please add to CC setup? #111

Mariusthvdb opened this issue Jan 28, 2019 · 5 comments

Comments

@Mariusthvdb
Copy link
Contributor

Mariusthvdb commented Jan 28, 2019

continuing from #108 (comment) and not knowing yet how to create a PR, I've managed to add the tholddark attribute of the ZLLLightlevel sensor to the list of attributes of the binary_sensor:

schermafbeelding 2019-01-28 om 09 16 12

schermafbeelding 2019-01-28 om 09 50 31

this is the code I used:

binary_sensor hue.py:

ATTRS = {
    "SML": [
        "light_level",
        "battery",
        "last_updated",
        "lx",
        "dark",
        "daylight",
        "temperature",
        "on",
        "reachable",
        "sensitivity",
        "threshold",
    ],
 
def parse_sml(response):
    """Parse the json for a SML Hue motion sensor and return the data."""
    if response["type"] == "ZLLLightLevel":
        lightlevel = response["state"]["lightlevel"]
        tholddark = response["config"]["tholddark"]
        if lightlevel is not None:
            lx = round(float(10 ** ((lightlevel - 1) / 10000)), 2)
            dark = response["state"]["dark"]
            daylight = response["state"]["daylight"]
            data = {
                "light_level": lightlevel,
                "lx": lx,
                "dark": dark,
                "daylight": daylight,
                "threshold": tholddark,
            }
        else:
            data = {
                "light_level": "No light level data",
                "lx": None,
                "dark": None,
                "daylight": None,
                "threshold": tholddark,
            }

and sensor hue.py:

ATTRS = {
    "SML": [
        "light_level",
        "battery",
        "last_updated",
        "lx",
        "dark",
        "daylight",
        "temperature",
        "on",
        "reachable",
        "sensitivity",
        "threshold",
    ],

template sensor:

      corridor_motion_sensor_threshold:
        friendly_name: 'Corridor threshold'
        value_template: >
          {{state_attr('binary_sensor.corridor_motion_sensor','threshold')}}

and for making the sensors look fancy:

homeassistant:
  customize_glob:
    sensor.*_motion_sensor_threshold:
      icon: mdi:altimeter
      templates:
        icon_color: >
          if (state > 25000 ) return 'rgb(85, 0, 0)';
          if (state > 20000) return 'rgb(255, 0, 0)';
          if (state > 15000) return 'rgb(255, 165, 0)';
          if (state > 10000) return 'rgb(0, 128, 0)';
          if (state > 7500) return 'rgb(255, 211, 30)';
          if (state > 5000) return 'rgb(255, 255, 0)';
          if (state > 25000) return 'rgb(30, 144, 255)';
          if (state > 1000) return 'rgb(30, 255, 255)';
          return 'rgb(47, 0, 0)';
@robmarkcole
Copy link
Owner

HI @Mariusthvdb happy to review a PR, but since my company is making my role redundant I am focussed on job appliations. Im confident you can do it :-)
Cheers

@yottatsa
Copy link
Contributor

Hi @Mariusthvdb, I'm happy to implement it.

Could you please write what do you try to achieve, because now I see the threshold field a bit inconsistent, as it shows the data in a different format, so you couldn't compare it to light level. Do you want to just control and display the value? Do you want some automation on top of it?

@Mariusthvdb
Copy link
Contributor Author

Mariusthvdb commented Jan 28, 2019

yes, I want to be able to set it, and in fact have built that too. see:

https://community.home-assistant.io/t/map-values-for-an-input-select/94354/19?u=mariusthvdb

below Update

the threshold field a bit inconsistent, as it shows the data in a different format,

its the unchanged data from the sensor, not really sure what you find inconsistent about it?
I've positioned the new threshold below sensitivity because they are both related to the settings, as opposed to the real-time state.

very nice to do that by means of this small selector set. Will do so later on in automations (where one can distinguish between low threshold and high threshold scenarios/scenes.

please note that I added the threshold both in if 'not none' and 'else'. Not sure if that is necessary, but since those are the data lists thought it might be good practice?

just to give you an idea of what possible right now:

schermafbeelding 2019-01-28 om 16 03 15

schermafbeelding 2019-01-28 om 16 03 08

@Mariusthvdb
Copy link
Contributor Author

HI @Mariusthvdb happy to review a PR, but since my company is making my role redundant I am focussed on job appliations. Im confident you can do it :-)
Cheers

o dear, best of luck!

yottatsa added a commit to yottatsa/Hue-sensors-HASS that referenced this issue Feb 6, 2019
@yottatsa yottatsa mentioned this issue Feb 6, 2019
@yottatsa
Copy link
Contributor

yottatsa commented Feb 6, 2019

state_attr("binary_sensor.bedroom_motion_sensor", "threshold") == 16000

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

No branches or pull requests

3 participants