Node red, Big timer to control the lights

No I think the problem was the repeat tickbox being on, even though you removed from bottom node group, it was still ticked on the top one and they were both connected to the same light.

I have not tried the dusk because I only tested mid morning today using times eg 11:30am, according to my timezone and the status under my bigtimer dusk doesn’t happen until another 2 hours and 12mins.

Screenshot_7

I tried to change one of the bigtimer to turn on at dusk.
image
But I got this immediately when I deploied.
image
And now it is in the morning where I live.
Dusk is not working for me.

I did quick google search and apparently today in stockholm dusk is at 23:39 and dawn is 02:01.

Your off time is 22:00 so therefore your lights are going to come on after your Off time.

The reason you see the On for 12hours and 19mins is because your lights would be in an on state because they would have turned on at 23:39 run all day and then turn off at 22:00 before turning on again at 23:39 running again all through the day till 22:00…

Okay, I did not think of that.
But result is the same if I change to off at sunset.
image
Shouldn’t that work?

If I set off att 23:45 it works!

Sunset is 22:08 Dusk is 23:39 your lights would turn off at 22:08 and then turn on at 23:39 and run for 23hours odd hours.

Dusk happens after sunset when it’s mostly night with just tiny bit of light left. I don’t like using dusk to turn on lights coz it’s pretty dark, I use sunset on all my events.

Yes, that’s apparently so!
What is then the best way to turn on the light when it starts to get dark.
In HA I use the sun angle.
But now I would like to start using Node-red instead.

Just use Sunset on the On Time as this is when the sun just goes under the horizon and the light starts fading from the sky.

You can also use the On Offset box in Bigtimer to fine tune eg you want 10mins after sunset just add that time in the On Offset box.

Thank you Three for all help

1 Like

Not a problem. Enjoy automating your lights!

Hello again Three,
When I catched how the BigTimer works and the problem with dusk and sunrise. I start to think about to use the sun elevation instead, as I have been doing in the HA.
I created following flow


Where the siwtch node checks if the sun elevation is above or below 4 degree.
But I have one problem output from the switch node is a number (angle) and not on/off as I would like it to be. Do you know how to achieve this?
Here is my flow:

[{"id":"56e7520e.6a15ac","type":"switch","z":"3a862370.85bf5c","name":"Sun Angle","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"4.0","vt":"num"},{"t":"gt","v":"4.0","vt":"num"}],"checkall":"false","repair":false,"outputs":2,"x":520,"y":660,"wires":[["943237b9.26c7e8","ca1578a6.141898"],["1fc17d03.197323","497b1af1.da3e24"]]},{"id":"943237b9.26c7e8","type":"api-call-service","z":"3a862370.85bf5c","name":"Wall Plug 8 on","server":"da215a6e.38deb8","service_domain":"homeassistant","service":"turn_on","data":"{\"entity_id\":[\"switch.wall_plug_8\"]}","mergecontext":"","output_location":"","output_location_type":"none","x":780,"y":653,"wires":[[]]},{"id":"1fc17d03.197323","type":"api-call-service","z":"3a862370.85bf5c","name":"Wall Plug 8 off","server":"da215a6e.38deb8","service_domain":"homeassistant","service":"turn_off","data":"{\"entity_id\":[\"switch.wall_plug_8\"]}","mergecontext":"","output_location":"","output_location_type":"none","x":780,"y":760,"wires":[[]]},{"id":"27ece0c2.8bbac","type":"debug","z":"3a862370.85bf5c","name":"SunAngle","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":520,"y":600,"wires":[]},{"id":"e6a77004.9b019","type":"inject","z":"3a862370.85bf5c","name":"8:15","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"15 08 * * *","once":false,"onceDelay":0.1,"x":510,"y":740,"wires":[["1fc17d03.197323"]]},{"id":"ec49b1df.1969e","type":"inject","z":"3a862370.85bf5c","name":"22:20","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"20 22 * * *","once":false,"onceDelay":0.1,"x":510,"y":780,"wires":[["1fc17d03.197323"]]},{"id":"ca1578a6.141898","type":"debug","z":"3a862370.85bf5c","name":"Sun below 4 degree","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":800,"y":620,"wires":[]},{"id":"497b1af1.da3e24","type":"debug","z":"3a862370.85bf5c","name":"Sun above 4 degree","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":800,"y":720,"wires":[]},{"id":"dffb5b9f.63f478","type":"server-state-changed","z":"3a862370.85bf5c","name":"Sun Elevation","server":"da215a6e.38deb8","entityidfilter":"sensor.sun_elevation","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":210,"y":660,"wires":[["27ece0c2.8bbac","56e7520e.6a15ac"]]},{"id":"da215a6e.38deb8","type":"server","z":"","name":"Home Assistant"}]

Annotation%202019-06-25%20194431
CHANGE node

Annotation%202019-06-25%20194533
search for whatever you want to look for in code that is coming in from the left and then change it to something else that goes out the right.

If the input < 4 shall be ON and > 4 shall be OFF
Can I also achieve that?

Probably use a SWITCH node first so your can filter on each output and then add a CHANGE node for each output from the SWITCH node. And on the CHANGE node because you have already predetermined the event when you filtered it in the SWITCH node, you can just change the dropdown box in the CHANGE node to SET and so whatever comes in on the left will get CHANGED to on or off when it leaves on the right.

Annotation%202019-06-25%20200414

Annotation%202019-06-25%20200456

Thanks now it works fine :slight_smile:

1 Like

Hi Three,
I have a new problem maybe you can help me with. :slight_smile:

I would like to control a wall plug on/off of a calculated on time for my laptop, i.e when the laptop has been on for 3 hours switch on the wall plug and charge the laptop for 1 hour then turn off the wall plug and stop charging the laptop. Restart the time calculation for the laptop on time and so…
In that way I don’t need to bother about the laptop charger be plugged in all the time.
I have the laptop in the same place all the time.

//Fredrik

You could employ a WOL Switch:


with the host option to check if your Laptop is turned on or off.
Then just employ the timer options you talked about based on the status of your laptop.

Or you could also just check if its connected to the network via device_tracker?

I where thinking of using the device_tracker.
But I don’t know how to solve to logic in node red with the times and so on.

Well… it depends how sophisticated you wanna do it.
I would employ timers for this.

i.e.: Checking the state of your device tracker. If this changes start a stoptimer (i.e.: 3h). When this has counted down, i would just send the service call to turn on the switch. You can again employ a timer for 1h to then turn it off again and restart the loop.

Here is an example of a Timer that i linked to a Motion Event (The formula part is to stop or reset the timer in case the motion goes ON again.)


[
    {
        "id": "68e14476.85e71c",
        "type": "server-state-changed",
        "z": "1579db1.3638e25",
        "name": "Motion?",
        "server": "2fba4297.e4145e",
        "version": 1,
        "entityidfilter": "group.motion",
        "entityidfiltertype": "substring",
        "outputinitially": true,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is_not",
        "outputs": 1,
        "output_only_on_state_change": false,
        "x": 50,
        "y": 80,
        "wires": [
            [
                "e1ff7f00.dd058"
            ]
        ]
    },
    {
        "id": "e1ff7f00.dd058",
        "type": "function",
        "z": "1579db1.3638e25",
        "name": "on/off?",
        "func": "newmsg = {};\nif (msg.payload == \"off\")\n{\n    newmsg.payload = \"True\";\n}else {\n    newmsg.payload = \"STOP\";\n    flow.set(\"motion\", 0);\n}\n\nreturn newmsg;",
        "outputs": 1,
        "noerr": 0,
        "x": 210,
        "y": 80,
        "wires": [
            [
                "bfc20533.d45cc8"
            ]
        ]
    },
    {
        "id": "bfc20533.d45cc8",
        "type": "stoptimer",
        "z": "1579db1.3638e25",
        "duration": "30",
        "units": "Minute",
        "payloadtype": "num",
        "payloadval": "1",
        "name": "",
        "x": 380,
        "y": 80,
        "wires": [
            [],
            [
                "583dba9b.d02d94"
            ]
        ]
    },
    {
        "id": "2fba4297.e4145e",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]

Marcus,
Thanks a lot,
To start with, how do I implement your code?
Do I copy and paste your code into a Function node?

//Fredrik