Hue motion sensors + remotes: custom component

@robmarkcole thanks. What I’m actually after is the ability to switch the sensor off as can be done through the official app (Accessory Setup) . I use a hue labs formula which controls certain lights, I’d like to programmatically disable the sensor from time to time through home assistant so the hue labs formula doesn’t kick in.

1 Like

@Cain that is possible via the API. Interested in submitting a PR?

Thanks for sharing this! Setting this up taken me big steps foward as a newbie in both my automations and in learning about HA in general.

Just a few question on the Hue Motion devices,

  1. The last_updated field is reurning the last seen time in the format, [‘2018-02-10’, ‘00:38:23’], including brackets and quotes. I would like to tidy up the formatting, but the main thing is the time is 13 hours out from local time, which I think is 12 hours off GMT plus daylight savings. Is there a way for the Motion to return local time, or convert the time to local time allowing for daylight saving?
  2. Is last_updated only updated when it sees motion? If so could it be polled every 10 minutes to use as a thermostat?

Hi @PEBKAC, thanks for your questions.
Re Q1.

The component doesn’t really do any formatting of the datetime data returned by the Hue API:

 'last_updated': response['state']['lastupdated'].split('T')}

Therefore the first thing to check is whether you have your timezone set in the Hue app? I’m happy to update the code to return an isoformat datetime ,but you would still want to use a template to put the formatting in whatever style you like. I believe this should handle timezoning also.

Re Q2:
That’s an interesting question, and the Hue docs don’t provide an answer as to when an update is triggered (motion, temperature, periodic) from what I can see, do you agree? However there is an API method to Update Sensor. If you want to implement this and submit a Pull Request on Github I am happy to consider it?
Cheers

1 Like

HI Rob,

Have been searching the Hue Api for the Hue.scenes which renders a daunting output.

The thing is the api is ordered by owners and the scenes are listed many times, per lights and other variable (hue labs, wakeup etc etc)

Would you know of a better way to extract the available scenes per light other than how i doit know through:

- platform: jsonrest
  resource: !secret hue_scenes_resource
  method: GET
  name: Philips Hue Scenes
  scan_interval: 30

the resource being of the format:

hue_scenes_resource: http://192.168.xxx.xxx/api/[apikey]/scenes/

Cheers,
Marius

Hi mate, I haven’t used scenes myself, is this not covered by the lights component?

Checked the Hue app and the city is correct.

Running http://192.168.1.99/api/[key] to the bridge provides a dump of the device configs from the Hue network. The bridge itself has a date/time value for the attribute “UTC” and the correct local date/time value in the attribute “localtime”. (Not sure if attribute/value are the correct terminology here, but hopefully it makes sence.) The details returned referring to the motion sensor look like they dynamically build calls to the bridge, some of which refer to /config/localtime.

So it looks like the motion sensor is storing any of it’s last_updated values as UTC.

Sorry, but I haven’t set up a Philips developer account yet, so can’t access the referenced material. But I have found mentions that the temprature and light level values are updated every 5 minutes. It seems that there are seperate last_updated attributes for motion, light levels and temprature. The last_updated attribute on my HA system only changes when the sensor sees motion. I will try and extract more legible attributes from the motion using the debug api when I get a chance to confirm if there are independant attributes.

If it’s a 5 minute sample for temprature that’s probably OK for most things. It might be good to force a poll for automations though. The downside of polling may be shortning the battery life??

You mentioned formatting the datetime. Do you know how to do this is HASSIO? All of the references I have found look like they use python functions such as strftime(), but these are not supported in HASSIO – or if they are Mr Thickey here can’t get them to work.

HI @PEBKAC sounds like good progress.
Re polling interval, I expect more frequent than 5 min polling would reduce battery life. Have you determined the required polling for your application?
Re formatting the datetime, can you give an example of an approach you have tried that did not work?
The template docs gives several examples that may help you out.
Cheers

# Timestamps
{{ value_json.tst | timestamp_local }}
{{ value_json.tst | timestamp_utc }}
{{ value_json.tst | timestamp_custom('%Y' True) }}

no i don’t think it is.
im hoping for a hue.hue_get_scene service to be available sometime soon, since the hue.hue_activate_scene is now.

Cheers,
Marius

1 Like

Had a quick play and found the following.

If I go to the URL http://[IPofHue]/debug/clip.html, and from that page to a GET with /api/[USERNAME from phue.conf]/sensors in the URL: field the Command Response shows the sensor states.

It provides states for the following as well as additional information,

  • Daylight
  • Temperature
  • Presence (activated by motion)
  • Lightlevel
  • State

Each of the items above has its own lastupadated field in UTC format.

The lastupdated that HASSIO is using always corresponds to the presence state. This is reproducible, and can be triggered by moving in from of the sensor.

With a bit of observation it will be easy to work out the polling interval for the other states. Is it possible to pull the lastupdated value for each of them though?

As for polling, it may be handy to poll manually at the start of an automation or script rather than increasing the polling time. If the temperature and lightlevels are polling every 5 minutes that is probably enough as it is.

Thanks for the pointers on the timers. This was when I was first starting out - so about a month ago. :grin: All of the refrences I could find were for strftime(), which was exactly what I wanted, but is not supported. Will play with the timestamp function on another project…

BTW – I see on the Philips developer hpme page they indicated a new version of firmware for the Hue bridge firmware (with some potential to break things) is pending, and changes to support third party products that conform to Zigbee 3.0. Be nice if support extened beyond just lighting products.

HI @PEBKAC thanks for your research and detailed explanation, I hadn’t realised that lastupdated varied by sensor mode. Also it is useful to know that the firmware will change, but fortunately the announcement states that the API will not change. However this component will need significant re-writing before it can be submitted as an official HA component. I will be focussed on making these changes and submitting a MVP before adding new features such as your request. Are you interested in helping with the development work? The first step will be to address an issue in the underlying phue library here:
https://github.com/studioimaginaire/phue/issues/126

Hi, I am reinstalling your component.

WIll this override the Philips command (that you program on the Hue app)?

Also I think is not possible to have like the same behaviour of the Hue App with multiple click (in Hue app when you click first button one time, two, three or 4 times you get different commands available)

Hi, this component only reads the state of the remotes, it doesn’t control them.
Currently single and double clicks are supported.
Cheers

1_click and 1_hold ?

That’s correct. I wasn’t aware that more clicks are possible

Hi @robmarkcole,
I was thinking about the temprature from the sensor, and it looks like it is polling regularly. So while the lastupdated value currently being read is refering to motion, the actual temprature itself is current, so it’s possible to still use it for automations.

1 Like

Yes, I think is only for the ON button (the 1) you can have click, double, triple and quadruple click.

Could you add this?

Please create an issue on the hue sensors GitHub repo, and il put it on my to do list.
However that list is quite long! Pull requests are always welcome too.
Cheers

Well is not an issue, your component works as intended. I will add a feature request

It doesn’t work that way, when you set it up with the hue app it cycles through different scenes each time you single click, the app lets you define 4 scenes to cycle through, you could use automations to do something similar but that functionality isn’t part of the remote so likely isn’t within the scope of this component.