How to convert a switch entity to a cover entity - tuya devices?

Hi there!
At my parents house they installed Tuya switches (MOES WiFi + RF curtain module - you can find it by this name on AliExpress) that manage both via Tuya App and via RF remote control of the shutters.

In fact you can raise, lower and stop the shutter via remote control or via app in the same way.

The original app looks like this:

I’m then doing an integration job inside one of their Home Assistant instances.

The official Tuya integration imports the following objects as switches and NOT as covers, hence I found this guide:

I based my code on the “garage door” example in the linked guide and found another example to compare with on the official forum. So I generated this code:

 - platform: template
    covers:
      finestra_grande:
        device_class: shutter
        friendly_name: "Finestra sala grande"
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.finestra
        close_cover:
          service: switch.turn_off
          data:
            entity_id: switch.finestra
        stop_cover:
          service: switch.turn_on
          data:
            entity_id: switch.finestra
        icon_template: >-
          {% if is_state('switch.finestra', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

I thought it was not necessary to create an on/off state sensor (as indicated in the offical guide) since the switch itself already has this state.

I would then manage the graphic part with the HACS component “Cover position preset row”.

At the moment I am writing this, the shutter is completely lowered. This is what I see via gui (The behavior of the keys is probably modifiable, but I’m sticking with the default for now - unless the keys are actually calling incorrect services?):

FKrsL64

When I press the arrow that goes down the shutter goes up. If I press the stop button, however, it does not stop. In fact, it does nothing and continues to go up. By trial and error I also tried to reverse the behavior, so open_cover becomes switch.turn_off but the behavior does not change.

Basically if I take the simple switch and turn it on (from off to on) the shutter goes up but I have no way to stop it EVEN turning off the switch, which in this case would make the shutter go down. So I have to intervene with the Tuya app and press the pause button.

I add that the default state of the switches is “off”.

So, at this point… Can someone help me to figure out this?

Thanks! :smile:

What you describe seems in line with the app UI.
The important part you’re missing is the equivalent of the “Pause” button.

Yes basically. I can’t figure out how to pause the rise or fall of the shutter.
But if there is a way to do it in the Tuya app… There will be a way to do it in Home Assistant as well. I guess.

Hi did you find a solution? I have a similar situation with my Aqara relay controller. I have them for some years to control my electric shutter/covers. It all worked with Mi Home app but I want to control it in home assistant with a cover button just like you. I can’t find a solution to convert “2 on off switches” to a cover switch.
Any help is appreciated :slight_smile:

I didn’t need it anymore because after some updates from Tuya integration now the objects are imported correctly as curtains

Either make a template cover (yaml) or use the switch as X integration (via the UI).

@petro
Could you please explain your suggestion further?

I´m also missing the switch interfaces of some Tuya (also some of MOES) devices… I have over 100 Tuya devices and as long I was using Tuya´s Smart Life app I took the workaround over Samsung´s Smart Things app - there were those switches (mostly) available. Unfortunately, that workaround doesn´t seem to work in HA.

And e.g. the entity cover.abc can only be controled in HA by mouse - AFAIK. But if you mean this “via the UI” can be used by automation, that would be cool… (although on the UI there is only up and down and no stop)

As long as I create for a given Tuya device (e.g. a cover) the needed scenes in Tuya´s Smart Life app, I can call those scenes in HA (actually, I’m using Node Red for automation) and it works fine, but…

In some cases I have to recognize when a device was used e.g. manually or by Alexa (thus, “outside” of the HA automation) and for that the switch interface has to be monitored…

Thank you

I’m sorry, I’m not really sure what you’re asking.

I was hoping your message

Either make a template cover (yaml) or use the switch as X integration (via the UI).

…implies how to solve the problem of the original poster as well as my one. My issue is describe in the last sentence:

In some cases I have to recognize when a device was used e.g. manually or by Alexa (thus, “outside” of the HA automation) and for that the switch interface has to be monitored…

…which is not covered in the Template cover.

Well your last sentence doesn’t make sense because context (what performed action) is provided on all home assistant domains (switch, light, cover, etc)

OK, then I have to search further for one, whom it makes sense…

I suggest you read the HA glossary so you can re explain your questions with the correct terminology. I’m fairly sure I can answer your question but you’re explaining things with terminology that you made up.

Not so: you can have triggers, conditions and actions for covers with state trigger, state condition and service call.

On many covers with only two buttons, pressing up/down while the cover is already moving up/down stops the cover. That may be the case for your device too.

Not so: you can have triggers, conditions and actions for covers with state trigger, state condition and service call.

I´m using my Tuya devices by the Tuya integration. For my MOES cover devices I get only the cover entities in HA, but the cover entities are pretty useless in Node RED.
I’m controlling them in Node RED by calling the scenes I’m created in Tuya´s Smart Life app - since I don’t know of any other alternatives for this. That´s way I asked for.

On many covers with only two buttons, pressing up/down while the cover is already moving up/down stops the cover. That may be the case for your device too.

No, the device has 3 buttons, the cover UI in HA has only 2.

Use cover.open_cover and cover.close_cover services. This is no different than switch.turn_on or switch.turn_off. There’s no reason you need switches.

Thank you, but the issue is not to open, close or stop the roller blinds (although doing it by the above mentioned way is definitely easier, since it doesn´t need the definition of the scenes in Smart Life).

As I said above, I want to know whether the roller blind was used (was e.g. moved up or down by the physical buttons of the roller blind switch - which can be e.g. the MOES WIFI roller blind switch) since the last automation was executed by HA.

Please remember:

  • Our roller blinds can be controlled by HA automation, manually by pressing the physical switch buttons and/or by Alexa (which executes Smart Life scenes).
  • If I want know whether or not the given roller blind was used by Alexa or manually, then I have to recognize those usages.
  • When I´m using one of the [open|close|stop]_cover services I get the very same state value (unknown) as when the roller blind is not in use.

Thus, I’m looking for ways to automatically recognize, when the motor of the roller blind is on (whatever trigger was used for it). If it is not during some HA/Node RED automation, then I know what I’m looking for (at the next HA/Node RED automation I have to handle it differently, compared to the case where last usage was triggered by HA).

As an example where it is needed:

  • I’m monitoring the position of the Sun and I’m calculating at which position it would shine into my office.
  • Let’s say, at some position of the Sun the roller blind shall come down to 20%.
  • Later the roller blind shall come further down to 30%.
  • If I know, since last setting it to 20% the roller blind was not used manually, then it is an easy math to find the 30%. If it was used lastly manually, then I’m rolling it up (max opening) and then rolling it down to 30%.

Regards

Yes, we are on the same page. As I said in my first comment to you, you don’t need a switch for that, every entity domain has context. It’s an object that’s passed around in scripts and automations that contains a user_id or parent_id. You can use those ids to determine the source. No ids means it was manually adjusted outside HA.

In Node RED context.id has a value, but:

parent_id: null
user_id: null

…as well during automation as during stand by as well as during manually triggered.

The trigger object contains the correct context, not the entity. It’s not available in node red.

Edit: state changed events may have it as well. That might be accessible in NR

No, I didn’t find a way for that in NR. I´m monitoring it by trigger: state and by events: state