Looking for a blocking node

You could create trend sensors to tell if it’s ascending or descending. It’s default is 2 samples and will be true if ascending. Use invert to make another that will be true if descending.

Yep. You could create such sensor from this flow itself too using an entity node and then check the current state of that sensor. That’s another option.

(I delete this example because the one at the bottom will behave better.)

I will try this later also.

I tested the version you had earlier, the last one of the previous post.
Here is the output of it:

It fired one closing while it was still opening, then went back to opening again.
I don’t have time to debug more as I need to go and drop of my son.

It could be that the sensor at some point measures the “other” way… I’ll look at that too later.

The only issue I can think of is sensor mpu doesn’t always represent the correct state and rolls back to a lower number when it shouldn’t.

If so, get the later example (deleted, check post 27) and set some timespan in the for field of the binary_sensor event state node, 1 second for example. If it still doesn’t work, set a couple of seconds and adjust the thresholds accordingly, and so on, until you find the right spot. I see it takes quite a long time for the pivot to open so it won’t be too much of an inconvenience to set this for field to even 5 seconds.

For what I see in the picture above, timespan should be of at least 2 seconds.

(I delete this example because the one at the bottom will behave better.)

Problem of adding a delay in the event state node is, when mpu fails to update properly, you’ll notice a delay in the actions. With this flow you will mainly notice a delay in the actions when you change the pivots direction midway in which case there’ll be a delay as long as at least the value of the trigger node. You won’t notice delays when going from -4 to 8 without interrupting it though, which I assume is your top priority. To adjust it to your needs you only need to modify the threshold values whithin each wait until node and, probably, the delay whithin the trigger node, the purplish one. Set the delay as low as possible. 5 seconds won’t hurt I believe.
EDIT

[{"id":"6a850623.075998","type":"server-state-changed","z":"ebd7f2e4.a2afc","name":"Trigger","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":190,"y":200,"wires":[["bc2e13dd.83b3e"]]},{"id":"bc2e13dd.83b3e","type":"switch","z":"ebd7f2e4.a2afc","name":"Opening or closing?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"data.old_state.state","vt":"msg"},{"t":"lt","v":"data.old_state.state","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":200,"wires":[["8e78b6be.de6e28"],["4442e428.df0a7c"]],"outputLabels":["Opening","Closing"]},{"id":"c30b422b.7d6e1","type":"comment","z":"ebd7f2e4.a2afc","name":"Create sensor","info":"","x":210,"y":120,"wires":[]},{"id":"df7c5f40.d2e5c","type":"ha-entity","z":"ebd7f2e4.a2afc","name":"Sensor","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"pivot up down"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"pivotState","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":880,"y":200,"wires":[[]]},{"id":"10df793a.b73347","type":"server-state-changed","z":"ebd7f2e4.a2afc","name":"Open?","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.pivot_up_down","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":190,"y":380,"wires":[["546cc848.3883e8"],["c9f266b4.64c968"]]},{"id":"d46b9075.9a5d7","type":"comment","z":"ebd7f2e4.a2afc","name":"Automation","info":"","x":210,"y":300,"wires":[]},{"id":"519ba7e0.301468","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"TV on","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":750,"y":340,"wires":[["1255d841.e5deb8"]]},{"id":"1255d841.e5deb8","type":"link out","z":"ebd7f2e4.a2afc","name":"Chromecast","links":[],"x":845,"y":340,"wires":[]},{"id":"42123804.76bab8","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"Chromecast off","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_off","entityId":"media_player.chromecast_kok","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":880,"y":420,"wires":[[]]},{"id":"f617af4c.aab6c","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"TV off","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":420,"wires":[["42123804.76bab8"]]},{"id":"ba5df4d9.223f28","type":"trigger","z":"ebd7f2e4.a2afc","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":775,"y":200,"wires":[["df7c5f40.d2e5c"]],"l":false},{"id":"8e78b6be.de6e28","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"pivot","propertyType":"flow","rules":[{"t":"neq","v":"opening","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":515,"y":180,"wires":[["de2bdc3b.9f653"]],"l":false},{"id":"de2bdc3b.9f653","type":"change","z":"ebd7f2e4.a2afc","name":"set to opening","rules":[{"t":"set","p":"pivot","pt":"flow","to":"opening","tot":"str"},{"t":"set","p":"pivotState","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":180,"wires":[["ba5df4d9.223f28"]]},{"id":"4442e428.df0a7c","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"pivot","propertyType":"flow","rules":[{"t":"neq","v":"closing","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":515,"y":220,"wires":[["82984a32.5fe5b8"]],"l":false},{"id":"82984a32.5fe5b8","type":"change","z":"ebd7f2e4.a2afc","name":"set to closing","rules":[{"t":"set","p":"pivot","pt":"flow","to":"closing","tot":"str"},{"t":"set","p":"pivotState","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":220,"wires":[["ba5df4d9.223f28"]]},{"id":"546cc848.3883e8","type":"ha-wait-until","z":"ebd7f2e4.a2afc","name":"Opening threshold","server":"9405c3fe.d0a6c","version":0,"outputs":1,"entityId":"sensor.mpu6050_accel_x","entityIdFilterType":"exact","property":"state","comparator":"gte","value":"1","valueType":"num","timeout":0,"timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":410,"y":340,"wires":[["996a779a.7ea608"]]},{"id":"996a779a.7ea608","type":"api-current-state","z":"ebd7f2e4.a2afc","name":"Binary on?","server":"9405c3fe.d0a6c","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pivot_up_down","state_type":"str","blockInputOverrides":true,"outputProperties":[],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":600,"y":340,"wires":[["519ba7e0.301468"],[]]},{"id":"c9f266b4.64c968","type":"ha-wait-until","z":"ebd7f2e4.a2afc","name":"Closing threshold","server":"9405c3fe.d0a6c","version":0,"outputs":1,"entityId":"sensor.mpu6050_accel_x","entityIdFilterType":"exact","property":"state","comparator":"lte","value":"6","valueType":"num","timeout":0,"timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":410,"y":420,"wires":[["f152f1d9.5ec4"]]},{"id":"f152f1d9.5ec4","type":"api-current-state","z":"ebd7f2e4.a2afc","name":"Binary off?","server":"9405c3fe.d0a6c","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pivot_up_down","state_type":"str","blockInputOverrides":true,"outputProperties":[],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":590,"y":420,"wires":[["f617af4c.aab6c"],[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I will try these sequences when I get home.

Just to give some answers.

Here is the graph of the sensor. I could not get history tab to load at all so this is the best I can give you.


(the tiny spike before the “tower” is me, I triggered it and then I realized I needed the computer in front of me to debug the nodes, so I swiveled it up again)

The time from -4 to 8 is 90 seconds as I can see it.
And looking at the graph its clear it fluctuates a bit.
I have tried (since start) to make that less with a filter in ESP-Home.

  - platform: mpu6050
    address: 0x68
    update_interval: 2s
    accel_x:
      name: "MPU6050 Accel X"
      id: "x"
      filters:
        - delta: 0.05
      on_value_range:
      - above: 6
        then:
          - switch.turn_on: sw
      - below: 6
        then:
          - switch.turn_off: sw

But perhaps if I set this delta to 0.5 instead? It will make it less sensitive, but also more accurate in a sense. And that also makes it possible to set a longer update frequency.
because it takes larger steps then it wont falsely trigger the wrong way, I think.
And regarding delays and such, no it doesn’t matter much.
I can just adjust the position the actions fire if I find the delays an issue.

I would leave the sensor as it is for now. The flow will take care of the rest and I would leave the purplish trigger node’s delay to 5s since it takes 8.2s to complete every step, 8.2s is long enough time for that 5 second delay to not disturb.

You are right about that. The problem is the pivot goes so slowly we need that 0.05 accuracy to know it’s moving. If you cut it down, the pivot will very often look like it stopped to NR eyes, since it’ll stay in the same value for too long.

Last debug window you shared, it took the sensor from step 1.32 to 5.49 to yield a bad reading, ~35s , so apparently it doesn’t happen all that often.

Yep, you can just adjust the thresholds.

The only problem my flow has is, suppose, you set the pivot to opening. Reach threshold 1, TV goes on, and at that very spot you set the pivot to closing. If you do that, it’ll take the TV at teast 5s to turn off ( will be five minutes if no bad readding takes place during that time, otherwise longer ). Same will happen the other side, if you move from 8 to -4 and change the pivot’s direction right when it reaches the upper threshold.

I don’t think this will be a problem for what you are trying to achieve though. During normal operation you’ll barely find any delay.

Hey @Hellis81 , regarding this:

Does 0.5 delta mean your sensor wil round its value to .1 or .5? I think you were right, it would be nice to round it to .1 and scan interval to 1.

As I understand it, it means if the value is say 1, then it will not update until until the value is more than 1.5 or less than 0.5

Then delta 0.1 and update interval 2s, I would sart with. My 2 cents

Hey hellis, regarding that, I believe you were right. The best would be to set delta to 0.5, update interval to 2-3s if possible and then remove the purplish trigger node from my flow. That would be the best approach.