dresden-elektronik / deconz-rest-plugin

deCONZ REST-API plugin to control ZigBee devices
BSD 3-Clause "New" or "Revised" License
1.9k stars 503 forks source link

Motion Sensor: only switch on light if lux is below level x #1448

Closed ottelo9 closed 5 years ago

ottelo9 commented 5 years ago

With my Hue Bridge and my Hue Motion Sensor I was able to set up the brightness level at which the Sensor should be inactive because its bright enough. But how can I set this in the Phoscon app?

manup commented 5 years ago

This is currently only possible by writing custom rules via REST-API, but not from the Phoscon App. Supporting the brightness sensor is on our near future todo list.

ottelo9 commented 5 years ago

Ok. Do I have a chance to do it via Homebridge (Eve App) or do I have to use FHEM?

ebaauw commented 5 years ago

You should be able to setup a HomeKit automation with a trigger on the motion sensor and a condition on the light sensor. Best calibrate the light sensor through the API, setting config.tholddark and config.tholdoffset, so that state.daylight and state.dark reflect the appropriate light levels (this is what the Hue app does under the hood).

ottelo9 commented 5 years ago

Ok, I'm actually trying to calibrate the motion sensor values. My light level is actually ~8417 = 7 lux and I want to enable the lights because its too dark. How to set up the both config values tholddark and tholdoffset correct or what does these settings mean exactly?

EDIT: config.tholddark means state.lightlevel must be below this threshold. Then state.dark becomes true. If the state.lightlevel is above config.tholddark + config.tholdoffset then state.daylight becomes true.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ottelo9 commented 4 years ago

@ebaauw Maybe you can help me: I'm now using Home Assistant to control some lights via the HUE motion sensors. Actually I use simple automations to switch on the light: If the state changed to 'on' and 'light_level' > xxx than switch on. However, I noticed that the value of 'light_level' does not appear to be updated immediately when the state changes from off to on. So sometimes it happens that the room is dark (because of some clouds) but light_level is e.g. 15 lux so the automation will not trigger my lights.

Does it work better if I calibrate the tholddark and tholdoffset values and use "dark" and/or "daylight" as condition? I think these two boolean flags will be updated immediately inside the motion sensor.

ebaauw commented 4 years ago

No, config.tholdoffset, config.tholddark, state.daylight, state.dark, and state.lux are handled by the REST API plugin; the sensor only reports and knows the state.lightlevel value.

I find the Hue motion sensor only senses the light level when it detects motion and once every five minutes for periodic reporting.

See https://github.com/ebaauw/homebridge-hue/issues/83 for an explanation on how to use the thresholds for automated control of lights based on light level.

Oh, I wouldn't recommend this, but if you really want to automate using the raw value instead of the dark and daylight attributes, better use lightlevel instead of lux. The former uses a logarithmic scale, better suited for how the human eye registers light level: greater granularity at lower light levels.

ottelo9 commented 4 years ago

@ebaauw Could you explain or give me a tip how to get the "lightlevel" value from the API in Home Assistant? Via a sensor template?

ebaauw commented 4 years ago

No, I don’t know Home Assistant.

ottelo9 commented 4 years ago

Ok I found something: https://www.home-assistant.io/integrations/rest/

Add this to configuration.yaml (xxx = API Key for deconz, 6=sensor ID)

sensor:
  - platform: rest
    resource: http://localhost:40850/api/xxxxxxx/sensors/6
    value_template: '{{ value_json.state.lightlevel }}'
    unit_of_measurement: 'light'
    scan_interval: 10
    name: 'FlurOG SensorOG LightLevel'

Convert lightlevel to lux = (10 (float(value_json.state.lightlevel) / 10000) -1) 10 => 10^(x)

PS And I found useful information on the philips dev page: LightLevel Explanation Typical light levels for indoor use cases