"mapping values are not allowed here" for curl in shell_command

I try to call a curl with the shell command but get the error “mapping values are not allowed here”. What’s wrong with these lines.I swapped ’ for " with the same result

#to run shell commands
shell_command: !include_dir_named shell/
  pvoutput_generation: "curl -d 'd={{now().strftime('%Y%m%d')}}' -d 't={{now().strftime('%H:%M')}}' -d 'v2={{sensor.sp14_energy_apparentpower|round(0)}}' -H 'X-Pvoutput-Apikey: {{states.sensor.pvoutput_api_key.state}}' -H 'X-Pvoutput-SystemId: {{states.sensor.pvoutput_system_id.state}}' https://pvoutput.org/service/r2/addstatus.jsp"

I’ve stumbled into the same error, with this – anyone have any clues?

shell_command:
  umbrel_getblockcount: curl -k "http://username:[email protected]:8332/" -d '{"jsonrpc": "1.0", "id": "homeassistant", "method": "getblockcount", "params": []}'

I think it might have something to do with the { character.

Just out of interest, could it be the quotes? Should have single inside double quotes maybe?

umbrel_getblockcount: curl -k "http://username:[email protected]:8332/" -d "{'jsonrpc': '1.0', 'id': 'homeassistant', 'method': 'getblockcount', 'params': []}"

I’m just guessing here.

1 Like

Tried that, still the same error…

Error loading /config/configuration.yaml: mapping values are not allowed here
in “/config/configuration.yaml”, line 60, column 127

Column 127 I think is the { so there must be a way to escape that for Home Assistant / yaml which I’m missing.

OK, I spent 2 days trying to POST to traccar server. I finally found a solution and wondering if you could use the same technique?

1 Like

Solution: Remove all spaces from the JSON payload. Dumb but true.

shell_command:
  umbrel_getblockcount: curl -k "http://username:[email protected]:8332/" -d '{"jsonrpc":"1.0","id":"homeassistant","method":"getblockcount","params":[]}'

The above code successfully passes Dev Tools yaml validation. Whereas…

shell_command:
  umbrel_getblockcount: curl -k "http://username:[email protected]:8332/" -d '{"jsonrpc": "1.0", "id": "homeassistant", "method": "getblockcount", "params": []}'

… fails.

1 Like

wtf; I’d never have considered this
thanks a lot

1 Like

I might be an idiot but I am a persistent idiot :slight_smile:

Glad to have helped (in a 3 year old thread lol!)