[Now includes sun elevation cover control] Whats wrong here?

Edit: Find the completed Cover Control here

Hi all,

I created this

[
    {
        "id": "f33a51af.7993c8",
        "type": "tab",
        "label": "Rollos mit der Sonne",
        "disabled": false,
        "info": ""
    },
    {
        "id": "461906f9.0db388",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Rollos rauf",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "open_cover",
        "entityId": "cover.somecover, cover.somecover, cover.somecover",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 690.5,
        "y": 129.99999237060547,
        "wires": [
            [
                "8084afa0.386248"
            ]
        ]
    },
    {
        "id": "710655f9.dacd1c",
        "type": "server-state-changed",
        "z": "f33a51af.7993c8",
        "name": "Sonnenstand",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "entityidfilter": "sensor.sonnenstand",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 104.36666870117188,
        "y": 319.83331298828125,
        "wires": [
            [
                "f1d5d3.2bf3f23"
            ]
        ]
    },
    {
        "id": "f1d5d3.2bf3f23",
        "type": "switch",
        "z": "f33a51af.7993c8",
        "name": "Über / unter Horizont",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "-2.5",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "-3",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 310.36663818359375,
        "y": 318.75,
        "wires": [
            [
                "3e4872cd.16a68e"
            ],
            [
                "70bfc34b.95ccdc"
            ]
        ]
    },
    {
        "id": "87145822.2832a",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Rollos runter",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "close_cover",
        "entityId": "cover.somecover, cover.somecover, cover.somecover, cover.somecover",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 703.3666381835938,
        "y": 423.33331298828125,
        "wires": [
            [
                "ee169274.754238"
            ]
        ]
    },
    {
        "id": "693f7a2e.9011e4",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Treppe auf 20%",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "set_cover_position",
        "entityId": "cover.treppe",
        "data": "{\"position\":\"35\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 700.3666381835938,
        "y": 198.33334350585938,
        "wires": [
            [
                "bed7afd4.dfe448"
            ]
        ]
    },
    {
        "id": "8084afa0.386248",
        "type": "debug",
        "z": "f33a51af.7993c8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 883.1666412353516,
        "y": 128.8333282470703,
        "wires": []
    },
    {
        "id": "bed7afd4.dfe448",
        "type": "debug",
        "z": "f33a51af.7993c8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 889.1666259765625,
        "y": 200.83334350585938,
        "wires": []
    },
    {
        "id": "ee169274.754238",
        "type": "debug",
        "z": "f33a51af.7993c8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 881.1666412353516,
        "y": 426.8333282470703,
        "wires": []
    },
    {
        "id": "3e4872cd.16a68e",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Morgens",
        "lat": "xx.xxxx",
        "lon": "y.yyyy",
        "startTime": "04:30",
        "endTime": "11:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 488.5,
        "y": 176,
        "wires": [
            [
                "461906f9.0db388",
                "693f7a2e.9011e4"
            ],
            []
        ]
    },
    {
        "id": "70bfc34b.95ccdc",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Abends",
        "lat": "xxxxx",
        "lon": "yyyy",
        "startTime": "16:00",
        "endTime": "23:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 497,
        "y": 423,
        "wires": [
            [
                "87145822.2832a"
            ],
            []
        ]
    },
    {
        "id": "7e24b1f3.1fe48",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]

It was working fine as long I was using above_horizon and beyond_horizon as an trigger. But as they did not match my needs, I decided to use sun elevation leverl and created an sensor in HA where I put that state:

  - platform: template
    sensors:
      sonnenstand:
        friendly_name: "Sonnenstand"
        unit_of_measurement: '°'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

The sensor seems to be working fine, however the automation never gets triggered. Now I have an idea why already: The sensor is only updated in intervals (I think because sun is only updated in intervals?) and therefore the sensor does not get each value (i.e. -2.8, -2.7, -2.6…) but only the value thats there when the update interval hits. So it happens that my sensor never gets set to the value I chose to trigger…

Any suggestions how to mitigate this? I thought of putting a < -2.5 instead of = -2.5 (like in an example here https://www.home-assistant.io/cookbook/automation_sun/). but then again this would be triggered on every update in the morning or evening that is below that value.

Next was that I thought that again could be mitigated by creating an input_boolean, that is switched on on the first occasion and switched off later (i.e. after the tim ranges I defined for morning / evening) and run the tasks only when the switch is off. That would work I think but seems like an overkill to me.

Any input is welcome :slight_smile:

yes you need to use <=-2.5 condition and depending on your use case, I can propose a few options.

  1. you want to run the automation only and only once in the evening and morning? then put a throttle node after the time switch and limit it for let’s say 6 hours. so automation opens the cover, then you close manually afterwards, then it stays open for 6 hours.
  2. you can check what is the current state of the cover with current state node. open it if it is closed, close it if is open.

another option is to use other nodes of nodered as trigger. big timer, schedex or sunevents are few. with one of them it is easier to define more detailed conditions. you can trigger the automation at sunrise, end of sunrise or 30 mins before/after sunrise/sunset etc etc…

1 Like

Thank you Serkan! Everything interesting options, I think in this particular case the throttle node will be the best option :slight_smile:

Will also give the Node Red options a try.

Hi,
@HorizonKane , I’m about to make something very similar based on sun elevation so I’ve got some questions :

  1. Can you share your final solution ?
  2. The sensor creation is really needed, there no way to extract this elevation data from sun.sun directly from node red ?
  3. What solution did you choose to trigger only one time the automation ?

Thank you :wink:

You could also use the blind-control node from the node-red-contrib-sun-position package. Very powerful and you can open / close the blinds by sun position (if it shines into you window or not).

1 Like

Hi Schmurtz,

I was busy for a while and missed your message. Do you still need my final solution? I would then copy it in for you.

Not the one you were talking to but please do! I try to achieve the same as you and Im fairly new (2 days) to Node-Red. I also don’t have a problem with the German Node-Names, as I’m German myself

There you go, let me know for any issues.

What the Alarmcheck does: When the Home Assistant alarm panel is set to alarm_away it will close ALL covers, including the ones on the balcony doors. If alarm is disabled, they will keep open. Just play around with it, its quite easy. You can also play with other sun elevation levels, may depend on your area and surroundings when you want them to close.

[
    {
        "id": "f33a51af.7993c8",
        "type": "tab",
        "label": "Rollos mit der Sonne",
        "disabled": false,
        "info": ""
    },
    {
        "id": "461906f9.0db388",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Rollos rauf",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "debugenabled": false,
        "service_domain": "cover",
        "service": "open_cover",
        "entityId": "cover.wohnzimmerfenster, cover.wohnzimmertuer, cover.kueche",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 855.1333312988281,
        "y": 259.99999237060547,
        "wires": [
            []
        ]
    },
    {
        "id": "710655f9.dacd1c",
        "type": "server-state-changed",
        "z": "f33a51af.7993c8",
        "name": "Sonnenstand",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "entityidfilter": "sensor.sonnenstand",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 75,
        "y": 377.83331298828125,
        "wires": [
            [
                "f1d5d3.2bf3f23",
                "18d2626.5198d9e"
            ]
        ]
    },
    {
        "id": "f1d5d3.2bf3f23",
        "type": "switch",
        "z": "f33a51af.7993c8",
        "name": "Über / unter Horizont",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gte",
                "v": "-3.2",
                "vt": "num"
            },
            {
                "t": "lte",
                "v": "-5",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 306.9999694824219,
        "y": 377.75,
        "wires": [
            [
                "33e95ef2.d21b72"
            ],
            [
                "d5a19603.c96ab8"
            ]
        ]
    },
    {
        "id": "87145822.2832a",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Rollos runter",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "close_cover",
        "entityId": "cover.erdgeschoss, cover.obergeschoss",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 875.9999694824219,
        "y": 471.33331298828125,
        "wires": [
            [
                "a4411a42.4c7ae8"
            ]
        ]
    },
    {
        "id": "693f7a2e.9011e4",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Treppe auf 20%",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "set_cover_position",
        "entityId": "cover.treppe",
        "data": "{\"position\":\"35\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 864.9999694824219,
        "y": 328.3333435058594,
        "wires": [
            []
        ]
    },
    {
        "id": "3e4872cd.16a68e",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Morgens",
        "lat": "51.16569",
        "lon": "10.45153",
        "startTime": "05:00",
        "endTime": "10:30",
        "startOffset": 0,
        "endOffset": 0,
        "x": 649.1333312988281,
        "y": 291,
        "wires": [
            [
                "461906f9.0db388",
                "693f7a2e.9011e4"
            ],
            []
        ]
    },
    {
        "id": "70bfc34b.95ccdc",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Abends",
        "lat": "51.16569",
        "lon": "10.45153",
        "startTime": "16:00",
        "endTime": "23:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 641.6333312988281,
        "y": 471,
        "wires": [
            [
                "87145822.2832a"
            ],
            []
        ]
    },
    {
        "id": "33e95ef2.d21b72",
        "type": "throttle",
        "z": "f33a51af.7993c8",
        "name": "",
        "throttleType": "time",
        "timeLimit": "7",
        "timeLimitType": "hours",
        "countLimit": 0,
        "blockSize": 0,
        "locked": false,
        "x": 404.6333312988281,
        "y": 297.99999237060547,
        "wires": [
            [
                "1c9da454.11ab0c"
            ]
        ]
    },
    {
        "id": "d5a19603.c96ab8",
        "type": "throttle",
        "z": "f33a51af.7993c8",
        "name": "",
        "throttleType": "time",
        "timeLimit": "7",
        "timeLimitType": "hours",
        "countLimit": 0,
        "blockSize": 0,
        "locked": false,
        "x": 369.6333312988281,
        "y": 449,
        "wires": [
            [
                "57352f74.9242f"
            ]
        ]
    },
    {
        "id": "328a6bfe.c41e14",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Rollos rauf",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "open_cover",
        "entityId": "cover.treppe, cover.wohnzimmerfenster, cover.wohnzimmertuer, cover.kueche",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 844.63330078125,
        "y": 182,
        "wires": [
            []
        ]
    },
    {
        "id": "bbc8137b.c8f0b",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Morgens",
        "lat": "51.16569",
        "lon": "10.45153",
        "startTime": "05:00",
        "endTime": "10:30",
        "startOffset": 0,
        "endOffset": 0,
        "x": 656.6333312988281,
        "y": 174.99999237060547,
        "wires": [
            [
                "328a6bfe.c41e14"
            ],
            []
        ]
    },
    {
        "id": "57352f74.9242f",
        "type": "api-current-state",
        "z": "f33a51af.7993c8",
        "name": "Alarmcheck",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "outputs": 2,
        "halt_if": "armed_away",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "alarm_control_panel.sunny_alarm",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 457.1333312988281,
        "y": 502,
        "wires": [
            [
                "70bfc34b.95ccdc"
            ],
            [
                "2a5e4ed0.fd8ec2"
            ]
        ]
    },
    {
        "id": "53a4d7af.c4f178",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Rollos runter",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "cover",
        "service": "close_cover",
        "entityId": "cover.erdgeschoss, cover.treppe, cover.wohnzimmerfenster, cover.kuechenfenster",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 877.6333312988281,
        "y": 553,
        "wires": [
            []
        ]
    },
    {
        "id": "2a5e4ed0.fd8ec2",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Abends",
        "lat": "51.16569",
        "lon": "10.45153",
        "startTime": "16:00",
        "endTime": "23:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 643.2666931152344,
        "y": 552.6666870117188,
        "wires": [
            [
                "53a4d7af.c4f178"
            ],
            []
        ]
    },
    {
        "id": "1c9da454.11ab0c",
        "type": "api-current-state",
        "z": "f33a51af.7993c8",
        "name": "Alarmcheck",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "outputs": 2,
        "halt_if": "armed_away",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "alarm_control_panel.sunny_alarm",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 494.6333312988281,
        "y": 236.99999237060547,
        "wires": [
            [
                "bbc8137b.c8f0b"
            ],
            [
                "3e4872cd.16a68e"
            ]
        ]
    },
    {
        "id": "6f061c14.cf98c4",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Licht an",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "debugenabled": false,
        "service_domain": "hue",
        "service": "hue_activate_scene",
        "entityId": "",
        "data": "{\"group_name\":\"Obergeschoss\",\"scene_name\":\"Gedimmt\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 815.6333312988281,
        "y": 695,
        "wires": [
            []
        ]
    },
    {
        "id": "f4b86de2.9965a",
        "type": "api-current-state",
        "z": "f33a51af.7993c8",
        "name": "Alarmcheck",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "outputs": 2,
        "halt_if": "armed_away",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "alarm_control_panel.sunny_alarm",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 464.6333312988281,
        "y": 696,
        "wires": [
            [
                "326d9b7b.da9154"
            ],
            []
        ]
    },
    {
        "id": "18d2626.5198d9e",
        "type": "switch",
        "z": "f33a51af.7993c8",
        "name": "Über / unter Horizont",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gte",
                "v": "-2.5",
                "vt": "num"
            },
            {
                "t": "lte",
                "v": "-1.5",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 304.6333312988281,
        "y": 597,
        "wires": [
            [],
            [
                "d374f298.fb3b6"
            ]
        ]
    },
    {
        "id": "a4411a42.4c7ae8",
        "type": "api-call-service",
        "z": "f33a51af.7993c8",
        "name": "Licht aus",
        "server": "7e24b1f3.1fe48",
        "version": 1,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.obergeschoss",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 1137.13330078125,
        "y": 470,
        "wires": [
            []
        ]
    },
    {
        "id": "d374f298.fb3b6",
        "type": "throttle",
        "z": "f33a51af.7993c8",
        "name": "",
        "throttleType": "time",
        "timeLimit": "7",
        "timeLimitType": "hours",
        "countLimit": 0,
        "blockSize": 0,
        "locked": false,
        "x": 376.6333312988281,
        "y": 645,
        "wires": [
            [
                "f4b86de2.9965a"
            ]
        ]
    },
    {
        "id": "326d9b7b.da9154",
        "type": "time-range-switch",
        "z": "f33a51af.7993c8",
        "name": "Abends",
        "lat": "51.16569",
        "lon": "10.45153",
        "startTime": "16:00",
        "endTime": "23:00",
        "startOffset": 0,
        "endOffset": 0,
        "x": 640.6333312988281,
        "y": 695,
        "wires": [
            [
                "6f061c14.cf98c4"
            ],
            []
        ]
    },
    {
        "id": "7e24b1f3.1fe48",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]
1 Like

Completely missed your answer!
Thank you very much! That will help me out a lot!
Yep, I have to change quite a few values because I live in a very open space witch huge windows and no sky/sun obstructions besides some trees. So there are some windows that need to gradually shut earlier then others.

1 Like

Welcome :slight_smile:

If you have any questions just ask. I don’t know if the throttle node might is the best solution here as it only allows a command to pass every 7 hours. I wanted to avoid the script to spam commands every few mins when the initial Sonnenstand Node changs. But so far it is working good, so I didn’t try to find another solution yet.

When I find the time to play around I will post any changes…

Edit: I figured out the 7 hour toggle ist quite fine as it is adjusted with the “Morgens” and “Abends” nodes. Just had to remembe8r what I did back then :smiley:

1 Like

Hi,

Just an update: Tomorrow in the morning my covers did not move. Reason: With my values they should have done that at 4:59, while my timechecks only allow it from 5:00. Just changed that to 4:30 to fix it (but thinking of changing the other values as 4:59 is quite early).

1 Like

Just looking at this flow and it’s exactly what I’d like to do, but is there a way of not having to create a sensor in HA itself but to simply having the entity sun.sun deliver its full message payload, and let the switch note filter by the elevation attribute?

Maybe, you juts have to try around. As long as you get the value, you can use it.

I never became a real Node Red expert and statt loving back to HA automations currently.