I'm very new to the Node-RED and Rpi, so I might be asking a lot, but any help I would appreciate very much.
So, up until now, I was controlling my Philips HUE lights through my phone and it's built-in light sensor, with an app called Tasker and 3rd party plugin for hue.
I built an array in Tasker in which, whenever I'm home (my phone connected to my wifi), a looping task and profile starts, in which every 13 seconds it checks the lux data, if it's above a certain value, it dimms the light, more above, it turns it off etc.
When I leave home (disconnected from wifi AND not in range of my home geolocation - Autolocation check), it turns the lights off.
I was also able to connect through Join a config, where whenever I launch VLC in windows (watching a movie), Eventghost sends a request to my phone to turn off the lighting looping task and profile, and turn off the lights except for 1, which becomes dimmed.
So basically I would wanna build an array where nodered checks the lux value every 10 seconds, reads value, if its more-less than x value, dimms/turns off etc the lights, and I can turn this loop on-off using either Join or tasker from phone, since I would wanna only automate the lights when I'm home (sending "xy" Join message to nodered turns off the lopp, sending "yx" Join message starts the loop).
My question is, how can I achieve this using a raspberry pi and a TSL2591 light sensor with Node-red?
Are you able to get data from the light sensor in node-red ?
If not, you should be able to use the exec node to run a command and read it's output (if you are able to run a command against the sensor) or use the gpio pin output.
Your HUE lights, are they connected through the official Philips Hue bridge? If so, take a look at the hue2mqtt library:
This will allow your Hue bridge to be controlled over MQTT, which is natively supported by Node-RED. Meaning you can do more or less the same as using the official tools. hue2mqtt is based on the official Philips supplied Java library.
So that's how you can control the actual lights. By publishing messages to the correct MQTT topic with this set up. The light sensor itself could be read out from GPIO, as the previous poster described. In between comes your flow.
I was able to play a round with it a bit, what I still don't know is how to make if this then that segments.
So I know you can make loops with eg. looptimer plugin, but how do I "code" that every time it needs to check the time-lux data, like in tasker on android it's easy, if time is inbetween 08.00-12.00 and lux is under 80 then lights brightness 60% etc?
Can I do it in only 1 function node? With a lot of if then segments?
You could do it in a function node, but take a look at the Switch first, it might suit you better. You probably need to hook several Switch nodes in a row though
Not so “of course” if you’re me I’m planning on using a hue motion sensor and hook it up to the rest of non-hue systematically, through Zigbee2MQTT, together with several other zigbee based products. Then have NR control everything through MQTT. It’s one of the more expensive motion sensors, but after seeing too many reviews of the Ikea Trådfri series my choice was made; that one if placed in an area with a lot of motion will eat the battery in a month if you’re lucky. Not going to risk that. I’m planning on faking the bridge, then hook it up to MQTT directly. Only buying a bridge if it turns out I truly need it
Your sensor produces lux values every x seconds, this you can use as a trigger for the flow.
I do the same here. I have a light sensor, if lux < 160 my lights turn on gradually based on the lux value.
First you need to have the light sensor producing data in node-red, did you accomplish this already ?
If yes, please post your flow so we can help you.
Wwell honestly, I firstly need to solder the parts of TSL2591 together, and I haven't recieved my soldering station yet, so no, but yes it seems like and "adventure" due to I can't find in nodered's palette manager a node for TSL2591.
How will you be connecting your TSL sensor? To the pi over GPIO? To an Arduino plugged into the pi? To something else entirely?
If Arduino, take a look at the serial I/O node and earlier topics about it.
If Pi, take a look at the RPI GPIO I/O nodes.
If something else, see how you can control the sensor through that thing. Then see if you can connect the thing to Node-RED through a similar way as mentioned above.
I will use female-female jumper cable to connect to rpi gpio
Pi 3V3 to sensor VIN
Pi GND to sensor GND
Pi SCL to sensor SCK
Pi SDA to sensor SDA
BTW, still haven't found a node to readout, have no idea what to write, a function maybe? Also, could someone tell me how to code that function to read a value out as a simple number?
I would wanna make a flow dependent on the lux (switch node), so a readout of a simple number.
Readout of the lux as a number (i dont know, string or number,I think it doesnt matter) --> switch "inbetween" x-y --> function node with code for rgb brightness etc --> changing light with Hue Group.
I've made plusieur test flows, based on time, injects from Join node, no problem, it flows flawlessly
Only thing to figure out is the lux data getting part.
With the lux data coming in from that sensor over GPIO, take a look at the nodes I linked above. They allow you to read values from GPIO, and write values to it.
There is no screen, maybe I'm using the wrong words here.
I only wanna know what's the current lux is. So that I can use that number with a switch node, that will part the flow to different settings of the lights.
So what you would like to do is read out the sensor value, of the sensor connected through GPIO. Have you looked into the specification of this sensor yet, and the values it is supposed to return? That could be something like a number between 0 and say 1000, or between 0 and 1, or something else completely depending on the sensor used. Start looking there. Your next step is reading up on how the reading from GPIO on the pi works, and reading up on using GPIO with node-red. Once you have that information, combine it together to write a function that gets the sensor value into something you can use. Formulas to convert raw sensor values are often described in the datasheet of the sensor, on the manufacturer’s website.
I got it working with a python library and script, which I've imported to node with pythonshell (it runs the script, gets msg.payload what the script prints)
My only problem is that its a string, not parted lux ir etc values, long string like this: