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

Add circadian lighting node #52

Closed
skylord123 opened this issue Aug 25, 2019 · 4 comments · Fixed by #64
Closed

Add circadian lighting node #52

skylord123 opened this issue Aug 25, 2019 · 4 comments · Fixed by #64
Assignees
Labels
🐛 bug Something isn't working

Comments

@skylord123
Copy link

skylord123 commented Aug 25, 2019

Is your feature request related to a problem? Please describe.
Currently I am using this for circadian lighting but the flow to calculate the percent of sun in sky is very long.

Describe the solution you'd like
It would be nice if there was a node offered that gave the height of the sun in the sky in percent (0~100 with 100% being at solarnoon and 0% being completely down). Here is the flow I am using right now to get this done. If I had a node for this it would save me 5 nodes in my flow alone.

It would also be nice to be able to pass the latitude and longitude in as an input for this node. If it is not passed in use the config but if it is passed in use that instead. I want to use this with Home Assistant which already has my home zone configured. I can poll for this information and pass it into the Node so whenever I update my home area it will update in Node-RED automatically (I would also recommend adding this to other nodes as well).
image

[{"id":"ddf5d091.adbae","type":"sun-position","z":"ff717302.0c688","name":"","positionConfig":"c94fc0b4.51c99","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"none","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"none","endOffsetMultiplier":60000,"x":450,"y":4360,"wires":[["463add7.cf2cb24"]]},{"id":"d7f1c60a.5026b8","type":"http in","z":"ff717302.0c688","name":"","url":"/manual_circadian_poll","method":"get","upload":false,"swaggerDoc":"","x":220,"y":4360,"wires":[["ddf5d091.adbae"]]},{"id":"38fbd466.c693bc","type":"sun-position","z":"ff717302.0c688","name":"sun-position solar noon","positionConfig":"c94fc0b4.51c99","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"none","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"none","endOffsetMultiplier":60000,"x":830,"y":4360,"wires":[["23c7623f.9a441e"]]},{"id":"463add7.cf2cb24","type":"change","z":"ff717302.0c688","name":"","rules":[{"t":"set","p":"sun_position_current","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"time","pt":"msg","to":"payload.times.solarNoon.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":4360,"wires":[["38fbd466.c693bc"]]},{"id":"23c7623f.9a441e","type":"change","z":"ff717302.0c688","name":"","rules":[{"t":"set","p":"sun_position_solarnoon","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":4360,"wires":[["ba25f13b.48342"]]},{"id":"ba25f13b.48342","type":"function","z":"ff717302.0c688","name":"calculate sun percent","func":"// distance of sun altitude from solar noon altitude percent (100% being at solarnoon 0% being completely down)\n\nvar sun_position_solarnoon = flow.get('sun_position_solarnoon');\nvar sun_position = flow.get('sun_position_current');\n\nif (sun_position.altitude > 0) {\n\tmsg.payload.percent = (sun_position.altitude / sun_position_solarnoon.altitude) * 100;\n    \n} else {\n\tmsg.payload.percent = 0;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1340,"y":4360,"wires":[["4b346b73.da84e4","b15aca03.212bd8"]]},{"id":"48833fa3.7b3db","type":"inject","z":"ff717302.0c688","name":"every 30 seconds","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":true,"onceDelay":"0.1","x":250,"y":4400,"wires":[["ddf5d091.adbae"]]},{"id":"4b346b73.da84e4","type":"debug","z":"ff717302.0c688","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1530,"y":4320,"wires":[]},{"id":"f148f3f6.1e357","type":"http response","z":"ff717302.0c688","name":"","statusCode":"200","headers":{},"x":1740,"y":4360,"wires":[]},{"id":"b15aca03.212bd8","type":"switch","z":"ff717302.0c688","name":"is HTTP request","property":"res","propertyType":"msg","rules":[{"t":"istype","v":"object","vt":"object"}],"checkall":"true","repair":false,"outputs":1,"x":1580,"y":4360,"wires":[["f148f3f6.1e357"]]},{"id":"c94fc0b4.51c99","type":"position-config","z":"","name":"","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"}]

Check the function blocks for more information on how my calculations are done.

Another option would be to just include this percent number in the output of the sun-position node. That way I only have to call it once instead of twice.

Describe alternatives you've considered
I have the flow that I posted above. I just think it could be easily shortened into one node. Circadian lighting node would be perfect for this library.

Additional context
I take the 0-100% and map it to a kelvin range 2500-5500. I think that part should be left to the user though and not included with this node.

@Hypnos3 Hypnos3 self-assigned this Aug 26, 2019
@Hypnos3 Hypnos3 added the 💡 enhancement New feature or request label Aug 26, 2019
Hypnos3 added a commit that referenced this issue Aug 29, 2019
@Hypnos3
Copy link
Collaborator

Hypnos3 commented Sep 24, 2019

The node gives now a "altitudePercent" property which hopefully meet your needs.

@Hypnos3 Hypnos3 closed this as completed Sep 24, 2019
@skylord123
Copy link
Author

@Hypnos3 finally got a chance to test this and the output is wrong.

This is what I am getting: 5501.141812875275
when it really should be this: 55.01141812875275

In my example I multiple by 100 and that works but for some reason when you are doing it in your code it actually didn't need it. I don't know why this is the case (would have to dig into the code further) but for now I am just dividing by 100 until this gets fixed.

Thanks for your work on this.

@Hypnos3 Hypnos3 added 🐛 bug Something isn't working and removed 💡 enhancement New feature or request labels Oct 25, 2019
@Hypnos3
Copy link
Collaborator

Hypnos3 commented Oct 25, 2019

Thank you, I will investigate this further.

@Hypnos3
Copy link
Collaborator

Hypnos3 commented Oct 29, 2019

OK, I have found a Bug, which will fixed with the next version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants