Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lights to percentage #7

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ HueToInflux
===========

https://github.com/GavinLucas/HueToInflux
-----------------------------------------

Script to take data from a Hue Bridge and post it to InfluxDB in order to view the data in Grafana.

Currently, it collects presence, temperature and light readings from Hue Motion Sensors and the brightness
of lights, but could be modified to collect other data from the Hue Bridge.

To create a username and pasword for the Hue Bridge, follow the instructions
To create a username and password for the Hue Bridge, follow the instructions
here: https://developers.meethue.com/develop/get-started-2/

To run the script:
- copy settings.json.example to settings.json and fill in the values. The 'sensors' section is for
remapping the names of sensors if you're not happy with the names in the Hue settings
- copy settings.json.example to settings.json
- Change the permissions of the file, e.g. `chmod 600 settings.json`, so that it's not readable
by other users
- Fill in the values for your Hue Bridge and InfluxDB
- Set the 'interval' to the number of seconds between each data collection
- The 'sensors' section is for remapping the names of sensors if you're not happy with the names in the
Hue settings. This is optional
- Install the requirements with `pip install -r requirements.txt`
- Leave it running in a screen session and sit back and watch the data roll in.
- Leave the script running in a screen session and sit back and watch the data roll in.

There are a couple of options that can be passed to the script to help you understand your data:

- To dump all the data from the Hue Bridge in order to see the names, etc., run `huetoinflux.py --dump`
and it will output all the data returned as json.

- To print the data rather than send it to InfluxDB, run `huetoinflux.py --print` and it will output the data
structure as json.
- To print the data rather than send it to InfluxDB, run `huetoinflux.py --print` and it will output the
parsed data structure as json.
4 changes: 2 additions & 2 deletions huetoinflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def parse_data():
elif device["type"] == "ZLLLightLevel":
data[name] = round(float(10 ** ((device["state"]["lightlevel"] - 1) / 10000)), 2)
elif device["type"] == "ZLLPresence":
data[name] = 254 if device["state"]["presence"] else 0
data[name] = int(1 if device["state"]["presence"] else 0)

for device in hue_data["lights"].values():
name = device_name_to_name(device["name"])
data[name] = device["state"].get("bri", 254) if device["state"]["on"] else 0
data[name] = int(device["state"].get("bri", 2.54) / 2.54) if device["state"]["on"] else 0

return data

Expand Down