How to check in an efficient way if a Philips HUE motion sensor detects motion? - sensors

I am coding a little app that is checking whenever a Philips HUE motion sensor detects presence in a quite reactive way.
At the moment I am polling its presence status every 2 seconds using the HUE V1 API: get-sensor
I am wondering if there is a better/efficient way to do it since this application is running on a little controller, so I would like to avoid to stress it with continuous polling and I also wondering if doing that will also drain out the sensor battery in a few days.

Related

VLC Timestamp export to notepad/excel via button

I'm working on analyzing traffic flow on 3 different bus stops as a research by watching recordings of it on VLC; I need to write down real-world timestamp of every bus stop and go along with a number of passengers boarding and exiting bus.
I'm looking for a way to speed things up by maybe using some kind of plugin in VLC player that would allow me to mark all these events with bound hotkey(s) and later export it to Excel/Notepad using offset time (I know the start time of recording, so I would export them in Excel with offset value in comparison to real-world timestamp). Timestamp format is hh:mm:ss, is there any way for this to work?

pausing device without visual cues

I'm doing a competition that requires our device to pause and stop midway on a pole. The device carries an increasing load (chain). The midway point is marked with a slight score mark (which we don't believe will be that noticeable). The device is supposed to travel up on the outside of the pole without pausing, pause on the way down and again on the way up, not pause going down the second time and then stop midway going up again.
I don't have experience with programming sensors and motors so, while I have ideas about how to do this, I don't quite know how to actually program this. There's a cap on the top I can use to switch direction of travel but the end of the pipe is open. I'm thinking of using either height off the floor or the weight of the chain as a constant to mark position along the pole. I'm having trouble finding inexpensive sensors so I don't have specifics.
Right now, I'm toying with the idea of using the switch at the top as sort of an on/off for the pausing/not pausing code. Alternatively, I can use the constant measurement (height/weight) to count the cycles and switch on the code that way. Is this an effective way of doing this? I'm looking at a raspberry pi to control everything.

Get data from Hue in realtime

I'm checking the hue API and I'm wondering if I understand it correctly that the motion sensor is able to switch lights on directly via the "rules", but it is impossible to get notified via the bridge about changes?
My scenario is that I would like to detect, if there is any motion and if not to turn my TV via its rest API off.
I also read that the sensor data are just updates every 5 minutes, how can I decrease the scan interval?
If you poll the Hue bridge via API, you instantly get the motion result.
It is as simple as that:
GET http://<bridgeip>/api/<userid>/sensors/<sensor-id>
{
"state": {
"presence": true,
"lastupdated": "2018-11-01T13:43:00"
},
...
}
For checking all 1 or 2 minutes, this will work fine (while my personal way of watching TV would not assure that the motion sensor detects my presence, as the chips are too fast gone).
However, this polling is the only way to retrieve events from Hue. If there is any need to use events instantly like e.g. the Hue dimmer switches etc. for external sources: Forget it. There is no syslog, no IFITT to the outside, no HTTP triggers, or anything you could use apart from polling. Philips answers these questions in the forum in a way:
We know the demand, it is on our roadmap, we do not commit to a date
Therefore: Buying Philips Hue sensors and switches is something which binds you to the ecosystem of the Hue Bridge.
You can achieve something like it by using Apple HomeKit-automations sending shell commands to your server – even though it is somewhat of a workaround...

how to detect power cycle on philips hue bridge?

How can I detect power outage on bridge? I tried using CLIP sensor daylight's lastupdated object and checked it against none but it does not help. As per meet hue description of 'lastupdated' object, it should none.
"Last time (based on /config/utc) the sensor send state data reflected in the state field. No value change is required to update the field. “none” (asof 1.x.0 null) when not initialized/no recent update has been received since the last bridge power cycle
"
But it always returns as timestamp. Can somebody suggest a way out please?
regards.
You can create a CLIPGenericStatus sensor and set it to a value that is not 0.
When the bridge restarts it will be 0 again.
You don't describe how you want to use this value (read it with by external process or trigger a rule on the bridge), but this is an indicator that you can use.
A Philips support developer recently came up with a solution on the meethue forums.
The idea here is that schedules start running when the bridge boots
and the state of a ClipGenericStatus sensor initiates its status to 0
after a reboot. This might be subject to change.
Create a ClipGenericStatus sensor.
Create a schedule that will change the status of the above ClipGenericStatus sensor to 1 every 10 to 15 seconds.
Create a rule that will do something with the lights when the above ClipGenericStatus sensor is equal to 1. The rule can for example
turn off all lights if the time is between 23.00 and 07.00. Some
downsides are:
It will also trigger when there is a reboot after disconnecting and connecting the powercord manually.
It will also trigger when there is a reboot after bridge firmware update or internal crash.
This isn't a solution for configurable startup behaviour.
Going back to last state, with saving all lightstates to a scene at a specific interval, is not recommended as it will degrade the life
expectancy of the lamps involved.
Link to original post: https://developers.meethue.com/comment/2918#comment-2918

How can I determine the length of time since the last screen refresh on X11?

I'm trying to debug a laggy machine vision camera by writing text timestamps to a terminal window and then observing how long it takes for the camera to 'detect' the screen change. My monitor has a 60hz refresh rate, so the screen is updated every ~17ms. Is there a way to determine at what point within that 17ms window the refresh timer currently is for an X11 application.
EDIT: After wrestling with the problem for nearly a day, I think the real question I should have asked was how to generate a visual signal that was sufficiently fast to test the camera images. My working hypothesis was that the camera was buffering frames before transmitting them, as the video stream seemed to lag behind other synchronised digital events (in this case, output signals to a robotic controller)
'xrefresh' is a tool which can trigger a refresh event on an X server. It does this by painting a global window of a specified color and then removing it, causing all subsequent windows to repaint. Even with this, I was still getting very inconsistent results when trying to correlate the captured frames against the monitor output, no matter what I tried to do, the video stream seemed to lag behind what I expected the monitor state to be. This could mean that either the camera was slow to capture or the monitor was slow to update. Fortunately, I eventually hit upon the idea of using the keyboard leds to verify the synchronicity of the camera frames. ('xset led' and 'xset -led'). This showed me immediately that in fact my computer monitor was slow to update, instead of the camera lagging behind.

Resources