Hue motion sensors + remotes: custom component

trying to refine my templates Im stuck with the way the component calculates lx from light_level, please have a look with me. This is the official Philips Hue table:

Philips Hue definition                 Lux               MeasuredValue
Overcast moonless night sky              0.0001                  0 dark.....
Outdoor: Bright moonlight                1                       1
Home: Night light                        2                    3000
Home: Dimmed light                      10                   10000
Home: ‘Cosy’ living room                50                   17000
Home: ‘Normal’ non-task light          150                   22000
Home: Working / reading                350                   25500
Home: Inside daylight                  700                   28500
Home: Maximum to avoid glare          2000                   33000
Outdoor: Clear daylight            > 10000                 > 40000
Outdoor: direct sunlight            120000                   51000

However, since the CC uses lx = round(float(10 ** ((lightlevel - 1) / 10000)), 2) there is no way I am ever going to get a lx value <1. Meaning, even when pitch dark 0 is measured for light_level, it will always be lx 1, which is 1 step up in the table…

Ideally Im am trying to reach a template for lx like the one I use for light_level (translated Overcast moonless night sky to dark for convenience sake):

      friendly_name_template: >
        Attic:
        {% set light_level = states('sensor.attic_motion_sensor_light_level')|int %}
        {% if light_level == 0 %} dark
        {% elif light_level <=1 %} bright moonlight
        {% elif light_level <=3000 %} night light
        {% elif light_level <= 10000 %} dimmed light
        {% elif light_level <= 17000 %} 'cosy' living room
        {% elif light_level <= 22000 %} 'normal' non-task light
        {% elif light_level <= 25500 %} working / reading
        {% elif light_level <= 28500 %} inside daylight
        {% elif light_level <= 33000 %} maximum to avoid glare
        {% elif light_level <= 40000 %} clear daylight
        {% elif light_level <= 51000 %} direct sunlight
        {% else %} too bright!
        {% endif %}

I can’t however build the same template for lx, have a look:

      friendly_name_template: >
        Attic:
        {% set lux = states('sensor.attic_motion_sensor_lux')|int %}
        {% if lux <=1 %} moonlight
        {% elif lux <=2 %} night light
        {% elif lux <= 10 %} dimmed light
        {% elif lux <= 50 %} 'cosy' living room
        {% elif lux <= 150 %} 'normal' non-task light
        {% elif lux <= 350 %} working / reading
        {% elif lux <= 700 %} inside daylight
        {% elif lux <= 2000 %} maximum to avoid glare
        {% elif lux <= 10000 %} clear daylight
        {% elif lux <= 120000 %} direct sunlight
        {% else %} too bright!
        {% endif %}

adding a first line to this template {% if lux <1 %} dark is useless, for it will never be <1… Mind you, this isn’t a silly detail, we can distinguish dark from moonlight with our eyes, and so does the hue sensor. Making it a float in the template doesn’t help, because of the way the rounding is done in the component…

might be able to do something with a template based in the light_level attribute, but feel this should really be refined in the component for lx value calculating. @robmarkcole @yottatsa what could we do to realize that?

thanks!

1 Like

This error showed back up in my logs again. It was what happened previously. If I was to venture a guess by some of the other templating I was fooling around with it would be that the entity is unavailable and returning none/null? I have always been trying to nail down issues with disconnecting devices and am still working through that. In any case should I define what should happen when none is returned for the template. How would that look?

   Error parsing value: 'value_json' is undefined (value: None, template: {{value_json.config.on}})
Connection lost. Reconnecting…

when does this show up? at startup, or during regular on-time.

if the first, it might be because the sensors havent been initialized yet, I get heaps of those during startup. (not the Connection lost. Reconnecting… though, that new to me)

not sure if you need to do anything when none is returned, does your system choke on it?

Hey everyone! Be nice I am new and this is starting to drive me absolutely nuts with trying to get the Hue Sensors working on home assistant ver. 0.89.2 (Hass.io for the pi).

So far I have followed instructions and put the following in but it still comes up and says the sensors can’t be found when I check config.

in /config/custom_components I have put the “binary_sensor.py” “device_tracker.py” and “sensor.py” (Both in a folder /custom_companents/hue and /custom_components/hue_custom with no luck)

In the configuration.yaml file I included the following;

In the group.yaml file I included the following; (obviously got no sensors to add since I can’t find them as active entities)

Since making the configuration.yaml point to /hue_custom it would appear when I check my configuration it doesn’t display the units as missing now; however, there are still some issues in the logs?

and

Anyway, I have likely missed a ridiculous little step, but your help would be greatly appreciated as it’s driving me bananas!

Hi, let’s go through this step by step - I may be duplicating what you have said, but lets do it :slight_smile:

The first thing is to create a folder under /config/custom_components called hue_custom

In this folder you need to put the following files:
binary_sensor.py
sensor.py
device_tracker.py

Next you need to go to the configuration.yaml (assuming it is one big file and not split out) and put:

binary_sensor:
  - platform: hue_custom
sensor:
   -platform: hue_custom
device_tracker:
   -platform: hue_custom

Check your config and restart HA.

If you are using HA and have SSH access while HA is restarting, tail the log in the /config directory:

tail -f home-assistant.log

Once it is up look for new entities in the developer tools:

33

Second from the left


You can search in the ‘Filter Entities’ bit if you want.

Sorry if this is dumbed down, but I have no knowledge of what you know and what you don’t - I hope it helps :slight_smile:

I think your config is wrong. You have the binary_sensor and device_tracker inside the sensor config. Yaml is sensitive to indentation.

sensor:
  - platform: hue_custom
binary_sensor:
  - platform: hue_custom
device_tracker:
  - platform: hue_custom
1 Like

Looking at it @tukadafoonday, @Gluwc is correct…no need for my long post lol. You need to put the platform in each sensor :slight_smile:

You guys are legends, thanks!

Long post back was fantastic! It provided good way to watch the log live when it cycled through.

Interesting why it hasn’t worked - here is what I had first (commented out) and what I used after which worked.

old config
Sensors

sensor:
  - platform: yr
  - platform: hue_custom
binary_sensor:
  - platform: hue_custom
device_tracker:
  - platform: hue_custom

New config

binary_sensor:
  - platform: hue_custom
sensor:
  - platform: hue_custom
  - platform: yr
device_tracker:
  - platform: hue_custom

If anyone can help me understand what I am missing as they look the same to me?

I also seen that I was missing a known_devices_yaml file.

thanks so much for all your help - it’s been two nights of me getting a headache to what I was doing wrong, reading a million forums, blah blah blah…

(I need to workout how to use the forum properly too - lol)

Is this in the configuration.yaml? or have you broken it down from the configuration.yaml - eg in my configuration.yaml I have

binary_sensor: !include binary_sensor.yaml
sensor: !include sensor.yaml 

etc.

I then have separate yaml files for each component. If you haven’t done this - don’t do it just yet as we need to get it working first :slight_smile:

If yo go to Configuration/General, and run a check config do you get any errors?

EDIT: What I am thinking is the custom component is ok, but another binary sensor etc is causing all the sensors to fail to load

It’s all working now with the “New Config” code but didn’t work with the “old config” code.

Not broken into separate files yet. I am very green as i’ve only set it up a week ago!

1 Like

Thanks for the reply and I apologize for my late reply. I also had experienced major delays when running HA on my Rpi3. Ever since I moved my installation to a VM on my Proxmox server (running on a Dell R210ii), I saw no more delays from the service as a whole. Heck… I can restart the VM in about 10 seconds. lol.

I just picked up a Hue motion sensor the other day so I’ll play around with it and HA and see what the delays are. Thanks.

1 Like

Moving on to my next brain injury - automation has been setup and looks to run in the logbook nicely; however, the service it calls for the light (it’s names correctly as far as I can tell) turns the light on; however, the light doesn’t turn on itself. Interestingly in the logbook it shows an icon as a little hamburger menu with a triangle rather than the light bulb when I turn the instance on with the entity switch.

configuration.yaml looks like this

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: -37.8071
  longitude: <longgggg>
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Australia/Melbourne
  # Customization file
  customize: !include customize.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Show the introduction message on startup.
introduction:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:
  base_url: &********
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem


# Sensors
binary_sensor:
  - platform: hue_custom
sensor:
  - platform: hue_custom
  - platform: yr
device_tracker:
  - platform: hue_custom

# Text to speech
tts:
  - platform: google

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

#Allow the configurator into the panel
panel_iframe:
  configurator:
    title: Configurator
    icon: mdi:wrench
    url: https://<IPAddress:port>
#Allow IOS companion
ios:

automations.yaml looks like this

- id: '1552993768853'
  alias: Pantry Light
  trigger:
  - entity_id: binary_sensor.pantry_motion_sensor
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: light.pantry_light
    state: 'off'
  action:
  - data:
      entity: light.pantry_light
    entity_id: light.pantry
    service: homeassistant.turn_on

and finally it’s throwing up some errrors in the home-assistant.log looks like this

and a photo of the automations logbook
automations%20logbook

Thanks again in advance! It’s all slowly making sense; however, these errors grind me to a halt :frowning:

use:

- id: 'Pantry light'
  alias: Pantry Light
  trigger:
    platform: state
    entity_id: binary_sensor.pantry_motion_sensor
    to: 'on'
  condition: [] #not really necessary
    #condition: state
    #entity_id: light.pantry_light
    #state: 'off'
  action:
    service: light.turn_on
    entity_id: light.pantry_light
     
1 Like

Thanks for answering. No it tends to come and go. I occasionally see messages that say HA cant connect to my bridge IP address so maybe that is related. All in all I’m thinking some issues are related to my infrastructure but of course these things can be difficult to nail down. Have I outgrown my pi and should I move on to a NUC(I ask myself). Is my router capable of handling my increasing number of devices or is HA in all of its lightning evolution the problem. In any case It seems like the template should define what to show when it gets a return of “nothing” like unavailable like with your lights but this is beyond my ability to template so far. You really have to become kind of become a small scale IT department when you take this on but its fun. My fiance thinks I’m crazy though lol. Still looking for that one automation that convinces her that I’m not wasting the hours I pour into this.

this is a very well down issue with the way HA integrates Hue, and there are many threads on this, it has not been solved yet. The unavailable Hue lights are a real pain…

to give you an idea…

Thank you very much - Please, let me know why the code didn’t work?

This has made everything absolutely so confusing now because I built that exact automation through the automations “wizard” you could call it.

Reading your code it all makes alot of sense, I just can’t workout why the other method would not work?

could you also let me know because I’ve found nothing too detailed; is there some documentation on the programming langauge and tags/etc you can use for them all? (Like for example the timer function)

thanks!

this was the main reason:

  action:
  - data:
      entity: light.pantry_light
    entity_id: light.pantry
    service: homeassistant.turn_on

the line with the entity: light.pantry_light shouldn’t have been there.

I always write my automations manually for I have an ‘order’ fetish, and am a sucker for as short as possible… It helps me writing correct automations, and spot errors as good as it gets. Always using the same order, with the corresponding spaces and indent (crucial in YAML) helps me prevent issues. But it’s personal of course. There are many ways to reach the same goal…

start here: Automating Home Assistant - Home Assistant and find your way in the components documentation: Timer - Home Assistant

I made the changes recommended in this thread and my Hue Switches are now working once more - but I have lost the ability to get them to display in their own tab.

e.g. I see an entry under ‘States’: sensor.conservatory_switch, and my automation scripts that use that sensor work, yet my groups.yaml contains (cut down for clarity)

default_view:
view: true
icon: mdi:home
entities:
- group.Hue

and

Hue:
view: yes
name: Hue Switches
entities:
- sensor.conservatory_switch

The tab shows nothing - whereas it used to show an entry to reflect each switch I have configured.

Is that kind of state display no longer supported, or does it require a config change?

TIA
Steve

Has anyone noticed any difference with Hue motion sensor on older version where they are sensors and on the newer version where they are binary_sensors?

I have automation that turns off lights according to humidity and with sensor that works really well but when motion sensors are binary_sensors once or twice a day the automation is not working and the lights are turning off even when there is motion. This is completelly fixed when downgraded back to 1.0.2 where motion sensors are just sensors.

I have the same problem with motion sensors not always triggering lights.