#mqtt.publish in button-card

1 messages · Page 1 of 1 (latest)

plucky pasture
#

Hi,

I am trying to set up a simple button for toggling my robot vacuum's mode between vacuum and vacuum_then_mop. But I cannot get it to to work using a JavaScript based approach.

This works fine:

double_tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    topic: valetudo/1stFloor/OperationModeControlCapability/preset/set
    payload: vacuum

But going through JavaScript to switch the mode does not:

double_tap_action:
  action: javascript
  javascript: |
    [[[
      const mode = states['select.valetudo_1stfloor_mode'].state == 'vacuum'
        ? 'vacuum_then_mop' : 'vacuum';
      helpers.runAction({
        'action': 'mqtt.publish',
        'service_data': {
          'topic': 'valetudo/1stFloor/OperationModeControlCapability/preset/set',
          'payload': mode
        }
      });
    ]]]
rustic pond
#

Where are you putting javascript? something custom?

plucky pasture
rustic pond
#

It's a core card. I'm not any kind of an expert but I have not heard of
action: javascript
Sounds like an LLM hallucination to me.

karmic heron
#

Generally when people say "button-card" I think more often then not they're referring to the custom:button-card, not the core Button card. It's an unfortunate alias of names.

#

But please be explicit.

plucky pasture