Read and Set Curtain Cover position (Aqara lumi.curtain.agl001)

I try to control a curtain using two ‘Aqara lumi.curtain.agl001’ motors. However I do not manage to set or get the cover position.

There is a service called “set_cover_position”, however I can not make that to work. I am using Node-red. And below some pictures of my actual test-setup.

Above you see that I did define three devices:

  • a button intended to set the cover position to “0” (closed)
  • a button intended to set the cover position to “100” (open)
  • and a slider to set the cover position to something between 0 - 100
    That does not work. Problem is that a / the position should arrive from the button / slider event, and I have now I idea how to do that

For reference the only thing I could get working (but what is NOT the intention), is a service node with a fixed position defined inside like this

For easier testing I also defined a simple setup like this

So the big questions are:

  1. how to pass a position value from some input (button / slider / etc) to the “set_cover_position service” !?
  2. and … if possible … how to read the actual position form the curtain motor !?
1 Like

You specify a message to pass through like this - you were very close.


See how payload replaced your number?

We get that payload by using the Current State node (there’s also a way to do it through global context but this is easier for basics.)


It’s very important to note here that as far as Node Red is concerned - unless you specify otherwise ALL states coming out of HomeAssistant nodes are strings unless you specify otherwise. This is one of those cases where it’s important. In the node above where we set the curtain - it’s expecting an Integer. And WILL ERROR if you send a string. String “0” is not 0… So we have to handle that. I chose in my example to set the output type for the Current State node to NUMBER which will handle the conversion for me and spit out a number. That’s a non default selection. You could also choose to handle the conversion some other way.

What am I pulling state FROM? This is reading an input_number helper:

So the net effect:

The inject node is just a trigger, which causes the state of the helper to be read - and set the curtain position to whatever number is currently set in the helper’s slider…

To read the state of the curtain you would also use a current state node.

Also for future questiosn when doing Node Red, post your code as follows:

[{"id":"f8d80a4791128aed","type":"api-call-service","z":"82c92ecd79347931","name":"Set Curtain Position","server":"79f56aab.e0b7b4","version":5,"debugenabled":false,"domain":"cover","service":"set_cover_position","areaId":[],"deviceId":[],"entityId":["cover.office_curtains"],"data":"{'position': payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":820,"y":160,"wires":[[]]},{"id":"dd0ca319c9443838","type":"inject","z":"82c92ecd79347931","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":160,"wires":[["9abf0980f0ad2958"]]},{"id":"9abf0980f0ad2958","type":"api-current-state","z":"82c92ecd79347931","name":"Get Curtain Setpoint","server":"79f56aab.e0b7b4","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.curtain_test","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":600,"y":160,"wires":[["f8d80a4791128aed"]]},{"id":"79f56aab.e0b7b4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

It makes it much easier to help you as opposed to a bunch of static images…

Good luck.

Thanks, I am learning. I can handle a sensor … However this curtain driver is different cake …

I need info how to control, read and write, that curtain driver (from within Node_RED). One of the issues I have is that I would like to know what the actual curtain position is.

Your example helps. It makes clear that I should use the ‘current sate node’ . However does that work in this case !? And if so how should I do that ??? To get info like:

  • actual slider position
  • actual firmware version
  • actual battery level
  • actual light intensity

And also the other way around, how to reach settings like

  • set current position as position 0
  • move to the left/right, stop. Set that position to position 100
  • set this is a left / this is a right cover

But lets start to find out how to get the actual cover position …

Same thing. Current state node - except the target is the curtain driver itself instead of the other entity I pointed at.

Not so sure.

I did create following test setup

With the following result

image

Content of the function node <<
node.warn('Message payload: ’ + msg.payload + ’ Topic: ’ + msg.topic);
node.warn('Message data: ’ + msg.data);
return msg;

That seems … not of any value

Don’t use a function node to grab the mesasge - Use a debug node set to expose the entire message:

image

It looks like this:

and will dump the ENTIRE message object, not just what’s in the payload…

Everything you ever wanted to know about your curtain driver…

And the code:

[{"id":"6ea8b8ac084f2d0c","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"4763d65072a81fd6","type":"inject","z":"6ea8b8ac084f2d0c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":360,"wires":[["52f045204f473def"]]},{"id":"52f045204f473def","type":"api-current-state","z":"6ea8b8ac084f2d0c","name":"","server":"79f56aab.e0b7b4","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"cover.office_curtain_rod_left","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":360,"wires":[["39b6d94a93e02153"]]},{"id":"39b6d94a93e02153","type":"debug","z":"6ea8b8ac084f2d0c","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"msg","x":740,"y":360,"wires":[]},{"id":"79f56aab.e0b7b4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Thanks !!, I was not aware of the output option ‘complete msg object’.

I put lots of effort in getting the curtain drivers working the way I want, but since it did not really work the way it should (very limited control via zha). I am trying alternatives to access the curtain driver.

  • I used to have an Sonoff dongle P, that worked a bit
  • I did flash that with new software, with little improvement
  • Than I bought the newer (advised) Sonoff dongle E, which in fact does not work at all :frowning:
  • so I installed MQTT / core-mosquitto, that is running, but I have now idea how to use it
  • so I consider going back to Sonoff donge E … which at least worked … a bit
    Drama …

I will open some separate questions … hoping to get good responces