Struggling with Script including a triggered automation - is that possible at all? :)

Any help for a newbie would be very appreciated - thank you!

I try making my first steps in HA using a vacuum communicating via MQTT. My intention is to do the following:

(1) Vaccum a room 2 times.
(2) Afterwards (!) mop it.

I made a script for (part 1) that finally calls up an automation (part 2) triggering to wait for the vacuum to return before beginning to mop.

Each, the script and the automation, work for itselves: but I am not able to call the automation from inside the script. And yes - as far as a newbie can - I read the HA informations about script- and automation-integration, but I suppose as someone with 0 programming experience there is a lack in my logic and this is not documented anywhere … :wink:

So if anyone could help my come a little bit closer to my goal - I would be very thankful! :slight_smile:

Kay

(1) This is the script code:

alias: Badezimmer reinigen
sequence:
  - service: mqtt.publish
    data:
      topic: valetudo/robot/FanSpeedControlCapability/preset/set
      payload: max
  - service: mqtt.publish
    data:
      topic: valetudo/robot/WaterUsageControlCapability/preset/set
      payload: off 
  - service: mqtt.publish
    data:
      topic: valetudo/robot/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": ["19"], "iterations": 2, "customOrder": true}'
  - delay: '00:00:15'
  - service: automation.badezimmer_wischen
mode: single
icon: mdi:bathtub

(2) And the automation:

alias: Badezimmer wischen
description: ''
trigger:
  - platform: mqtt
    topic: valetudo/robot/StatusStateAttribute/status
    payload: cleaning
    encoding: utf-8
action:
  - wait_for_trigger:
      - platform: mqtt
        topic: valetudo/robot/StatusStateAttribute/status
        payload: docked
        encoding: utf-8
  - service: mqtt.publish
    data:
      topic: valetudo/robot/FanSpeedControlCapability/preset/set
      payload: low
  - service: mqtt.publish
    data:
      topic: valetudo/robot/WaterUsageControlCapability/preset/set
      payload: high
  - service: mqtt.publish
    data:
      topic: valetudo/robot/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": ["19"], "iterations": 2, "customOrder": true}'

you need to trigger the automation

service: automation.trigger
target:
  entity_id: automation.badezimmer_wischen

but why you are not just adding the steps into your script?
the autmation does not make sense for me

Because HA does not accept the script code, when I insert something like “automation:”…

… or is there any way to insert a trigger directly into a script?

you could do it with a condition instead of wait for trigger

Okay, but I have not Idea how to implement the condition with kind of “wait for condition”? Or is a condition always a state that is waited for?

sorry, you are right. this will not work. it will not wait

but you can add a wait for trigger in the script

Okay, I See… What do you think: like this?

alias: Badezimmer reinigen TEST
sequence:
  - service: mqtt.publish
    data:
      topic: valetudo/robot/FanSpeedControlCapability/preset/set
      payload: max
  - service: mqtt.publish
    data:
      topic: valetudo/robot/WaterUsageControlCapability/preset/set
      payload: 'off'
  - service: mqtt.publish
    data:
      topic: valetudo/robot/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": ["19"], "iterations": 2, "customOrder": true}'
  - delay: '00:00:15'
  - alias: "Wait for Vacuum to return and being docked" 
    wait_for_trigger:
      - platform: mqtt
        topic: valetudo/robot/StatusStateAttribute/status
        payload: docked
        encoding: utf-8
  - service: mqtt.publish
    data:
      topic: valetudo/robot/FanSpeedControlCapability/preset/set
      payload: low
  - service: mqtt.publish
    data:
      topic: valetudo/robot/WaterUsageControlCapability/preset/set
      payload: high
  - service: mqtt.publish
    data:
      topic: valetudo/robot/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": ["19"], "iterations": 2, "customOrder": true}'
mode: single
icon: mdi:bathtub

Just tried it: Does not work :frowning:
(While “Script =calls=> automation” works!!)

Any idea how to make this more elegant second method (without automation-detour) work?

YIPEEEE - WORKS like this:

alias: Badezimmer reinigen TEST
sequence:
  - service: mqtt.publish
    data:
      topic: valetudo/robot/FanSpeedControlCapability/preset/set
      payload: max
  - service: mqtt.publish
    data:
      topic: valetudo/robot/WaterUsageControlCapability/preset/set
      payload: 'off'
  - service: mqtt.publish
    data:
      topic: valetudo/robot/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": ["19"], "iterations": 2, "customOrder": true}'
  - delay: '00:00:15'
  - wait_for_trigger:
      - platform: mqtt
        topic: valetudo/robot/StatusStateAttribute/status
        payload: returning
        encoding: utf-8
  - service: mqtt.publish
    data:
      topic: valetudo/robot/FanSpeedControlCapability/preset/set
      payload: low
  - service: mqtt.publish
    data:
      topic: valetudo/robot/WaterUsageControlCapability/preset/set
      payload: high
  - service: mqtt.publish
    data:
      topic: valetudo/robot/MapSegmentationCapability/clean/set
      payload: '{"segment_ids": ["19"], "iterations": 2, "customOrder": true}'
mode: single
icon: mdi:bathtub

Deleted the “alias”-part and perfect!!!

:)))

Thank you very much!!

1 Like