MQTT trigger command line switch syntax

Hello,

I’m trying to set up a simple automation rule that when a message is a published to a MQTT topic, a script is run via command line. I’ve tested command line switch manually (via webui toggle) and it works fine, but my automation rule is not working.

When I test the broker using simple commands from terminal (outside of HA), it works fine. So I’m not sure if it’s my syntax is an issue or HA isn’t communicating with the MQTT broker or how to check?

Here is my config for MQTT broker, switch then the automation rule

mqtt:
  broker: 192.168.1.31
  port: 1883
  client_id: home-assistant
  keepalive: 60
  protocol: 3.1

switch:
  platform: command_line
  switches:
    testi:
      offcmd: "/path/to/script"

automation:
  trigger:
    platform: mqtt
    topic: /test
  action:
    service: switch.testi.turn_off
    data:
      entity_id: switch.testi

Thanks for any advice

I guess it was my syntax. To anyone who finds this later, entity id is enough to reference the switch so service field should be:

service: switch.turn_off