Service as a trigger in an automation

Hi,

I have a roller shutter with a zigbee switch. When I open or close the shutter, I have to press stop to be able to do the opposite action.

I want to know if it is possible to automate the stop after the triggering of the open or close.

Can an automation use a service as a trigger ?

For instance, like this ? :

trigger:
  - service: cover.open_cover
      target:
        entity_id: cover.volet_salon
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: cover.stop_cover
    target:
      entity_id: cover.volet_salon

If yes, how can i use a service as a trigger please ?

Thanks a lot

You could try a timer then use trigger IDs to control it, something like this maybe?

alias: Stop cover after 30 seconds
description: ""
trigger:
  - platform: state
    entity_id:
      - cover.volet_salon
    from: "closed"
    to: "open"
    id: Cover-on
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.cover.volet_salon
    id: Cover-Off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Cover-on
        sequence:
          - service: timer.start
            data: {}
            target:
              entity_id: timer.cover.volet_salon
      - conditions:
          - condition: trigger
            id: Cover-off
        sequence:
          - service: cover.stop_cover
            data: {}
            target:
              entity_id: cover.volet_salon
mode: single

You would need to make a timer in helpers and make sure you check restore.

Maybe this ?

alias: Stop cover after 30 seconds
trigger:
  - platform: state
    entity_id: cover.volet_salon
    from: "closed"
    to: "open"
    for:
      seconds: 30
action:
  - service: cover.stop_cover
    entity_id: cover.volet_salon

Thanks for you help.

The problem is that when I open the shutter with the zigbee switch, as long as I don’t press stop, Home assistant does not know that the shutter is open (on my dashboard it is always closed).

So I don’t know if i can use a state trigger with “from: closed to: open”. Do you see what i mean ?

The only thing that i could use is when the services “cover.open_cover” or “cover.close_cover” start and begin a timer of X seconds and finally stop the shutter.

OK what about using the zigbee button as the trigger ? I assume you have some automation already using the zigbee button so tag this on the end

Which zigbee switch are you using and how is it connected to the blind ?

action:
  - service: cover.open_cover
    entity_id: cover.volet_salon
  - delay: "00:00:30"
  - service: cover.stop_cover
    entity_id: cover.volet_salon

Actually i use this integration :

It works well but only if i don’t use the switch on the wall. So it’s not practical if we want to use both HA and the physical switch.

My zigbee switch :

It’s connected with a conbee 2 plugged into a raspberry pi 4.

So that i want :

  • I open/close the shutter with the button on the switch or in HA or with siri
  • the service “cover.stop_cover” starts after X seconds (for not doing this manually)

Assume you are using ZHA ? What does the cover entity look like in dev tools ?

I don’t know if this is what you want :

It can listen for the event produced when a service is called.

alias: example
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: "cover"
      service: "open_cover"
action:
  ... etc ...
2 Likes

@123 that’s a good news. Maybe this is what i need ! So if i do this, it will works ?:

alias: "stop cover after opening"
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: "cover"
      service: cover.open_cover
action:
  - service: cover.stop_cover
      target:
        entity_id: cover.my_cover

What means “domain” ? what i have to put here ?

Thanks

alias: "stop cover 30 seconds after opening"
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: "cover"
      service: "open_cover"
action:
  - delay:
      seconds: 30
  - service: cover.stop_cover
    target:
      entity_id: cover.volet_salon

If you have more than one cover, the automation must be enhanced because it currently will trigger for cover.open_cover called for any cover.

I’ve a similar problem in the past and it was fixed with this:

alias: Home - Covers - Reset when stuck in a state
description: ""
trigger:
  - platform: state
    entity_id:
      - cover.lumi_lumi_curtain_agl001_cover
      - cover.bedroom_curtains_dual
      - cover.bedroom_curtain_left
      - cover.bedroom_curtain_right
      - cover.living_room_blinds
      - cover.living_room_blind_right_cover
      - cover.office_roller_blind_cover
      - cover.living_room_blind_left_cover_2
      - cover.gaming_room_blind_2_cover
      - cover.gaming_room_blind_1_cover
      - cover.gaming_room_blinds
      - cover.living_room_blind_centre_cover
      - cover.bedroom_curtains
      - cover.office_shutter_cover
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: cover.stop_cover
    target:
      entity_id: "{{ trigger.entity_id }}"
mode: parallel
max: 15

I’m basically monitoring all the covers and if one changes it state for 1min the automation will send it a stop command.

Ok, thanks. Yes i have severals covers.

I will test it.

But what does it mean the « domain » section in event_data ?

@EdwardTFN Ok but in your case it’s assuming that in HA the state of your cover change automatically when it get down or up no ?

The following list contains a few examples of domains:

light
switch
lock
cover
input_boolean

Ok thanks.

I think it’s not a big problem because the action is just to stop a cover. So if it’s stop another cover already stop or open, it’s not a problem I think.

This is the point
 It updates sometime, but sometimes it says with state “moving” up or down forever (or for really long time) and I cannot send new commands until it realized the previous movement already finished.
So I send a stop command in all cases. I know sometimes the command is sent unnecessarily, but as this is working quite reliable since a while I never touched this automation.

Ok so in my case it will be :

alias: Stop cover
description: ""
trigger:
  - platform: state
    entity_id:
      - cover.volet_salon
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition: []
action:
  - service: cover.stop_cover
    target:
      entity_id: "{{ trigger.entity_id }}"
mode: parallel
max: 15

What is max: 15 ?

And “for:” means after X seconds ?

That means if your cover changes state again it will run another instance of this automation in parallel (mode: parallel), but with a maximum of 15 instances.

In that example it means 0 hours + 0 minutes + 30 secs, or, 30 secs.

If Home Assistant doesn’t know the shutter was opened, a State Trigger won’t be able to detect when it’s open.