#run different script based on state in custom:button-card

1 messages · Page 1 of 1 (latest)

flat basin
#

Hi,

I want to run different scripts when clicking a button based on whether my robot vacuum is docked or cleaning. According to the documentation, this should be possible by using a javascript action. Given the following code, the confirmation is asked for correctly. But after confirming, nothing happens. Can someone help me out here?

- type: custom:button-card
  name: Kehrbert
  entity: vacuum.valetudo_1stfloor
  ...
  tap_action:
    confirmation:
      text: |
        [[[
          let state = states['vacuum.valetudo_1stfloor'].state;
          if (state == "docked") {
            return "Start cleaning?"
          } else if (state == "cleaning") {
            return "Cancel cleaning?"
          }
        ]]]
    action: javascript
    javascript: |
      [[[
        let state = states['vacuum.valetudo_1stfloor'].state;
        if (state == "docked") {
          return {
            "action": "call-service",
            "service": "script.valetudo_clean_segments",
            "service_data": {
              "vacuum": "1stFloor"
            }
          };
        } else if (state == "cleaning") {
          return {
            "action": "call-service",
            "service": "script.valetudo_cancel",
            "service_data": {
              "vacuum": "1stFloor"
            }
          };
        }
      ]]]