Help with Shell commands

Hi there !

I plan to use this terminal command on automation.
1st step is to create shell command.

I have this message :

“Invalid config for [shell_command]: expected dictionary for dictionary value @ data[‘shell_command’]. Got [{‘mesure_forced’: “mosquitto_pub -h my_ip_address -p PORT -m “” -t ‘blueriiot/commands/release_last_unprocessed/ID’ -u ‘username’ -P ‘password’”}]. (See /config/configuration.yaml, line 50).”

Here is the command to execute :

mosquitto_pub -h my_ip_address -p PORT -m “” -t ‘blueriiot/commands/release_last_unprocessed/ID’ -u 'username' -P 'password'

Ok on terminal but not on config.yaml

Regards

You have written something incorrectly to get that error message. Please paste that section of your configuration.yaml, properly formatted using the </> button or by surrounding with three backticks (```). Formatting should look like this:

shell_command:
  mesure_forced: [etc]

I write this on config.yaml

shell_command:
  - mosquitto_pub -h my_ip_address -p 1883 -m “” -t ‘blueriiot/commands/release_last_unprocessed/ID’ -u ‘username’ -P ‘password$'"

Lots of mistakes there, and that code (without mesure_forced) didn’t generate that error message (with mesure_forced).

  • no name for the shell command;
  • “smart” quotes which are probably copy-paste form the forum post. You must use simple single and double quotes: ' and ", not or ;
  • double quote at the end that doesn’t match with anything earlier.

Should look like this, as per the docs:

shell_command:
  mesure_forced: mosquitto_pub -h my_ip_address -p 1883 -m '' -t 'blueriiot/commands/release_last_unprocessed/ID' -u 'username' -P 'password$'

That should work if your HA installation has mosquitto_pub in its internal shell path. If it doesn’t (and perhaps a better alternative anyway) is to use the mqtt.publish service:

Helpfull answer, no error now :wink:

When i use this command on Terminal, it succeed.
But publishing via MQTT is interesting.
Could you give me the way to do this please ?

Just call the service in an automation. I don’t know how you do that with an empty message though.