Totally lost with simple automation

I am new to ZHA and trying to learn the system. I am a dev myself but there are so many options I am not sure where to do what…

I am lost with when to use the UI, Scripts, Templating to just do one simple task.

When I click on the button it should open the curtain, if its already open it should close it.

I have one aqara button and one curtain. Both are added (zigbee2mqtt).
I just made a simple automation and want to change the position variable based on the “open or closed” state of cover.0x04cf8cdf3c7555ca.


alias: Curtain Button
description: ''
use_blueprint:
  path: Drafted/aqara-buttons-all-in-one-zigbee2mqtt.yaml
  input:
    action_sensor: sensor.curtain_action
    single_action:
      - device_id: 353c3ab81c9f01e4482c13256f7fb740
        domain: cover
        entity_id: cover.0x04cf8cdf3c7555ca
        type: set_position
        position: 0

Any pointers ?

Not without knowing the Blueprint at Drafted/aqara-buttons-all-in-one-zigbee2mqtt.yaml. As it is not delivered by default, you must have added it.

Further to that, there is a cover.toggle service, so not sure what the blueprint achieves above that.

Thanks for the answer guys…

@koying not sure what you are referring to and that has probably to do with my lack of knowledge

You’re calling an action, currently

      - device_id: 353c3ab81c9f01e4482c13256f7fb740
        domain: cover
        entity_id: cover.0x04cf8cdf3c7555ca
        type: set_position
        position: 0

That action does a single thing: It always set the position to 0 (not sure if that’s open or close)

If you replace by

    - service: cover.toggle
      target:
        entity_id: cover.0x04cf8cdf3c7555ca

It should actually toggle between opened and closed each time you press the button

1 Like

Thanks it toggles indeed to close but it doesnt open anymore after it. It just tries to close it again.

 input:
    action_sensor: sensor.curtain_action
    single_action:
      - service: cover.toggle
        target:
          entity_id: cover.0x04cf8cdf3c7555ca
        data: {}

If toggle doesn’t work you will need to “choose” action (see choose action based on the current position. So you would setup the choose use a condition that checks if position=0 and then executes open, otherwise executes close. I’m afraid I can’t help you with the exact syntax, but you can probably work that out by using the GUI for making an automation and setting it up there and then copying it from the YAML.