nukeman
(nukeman)
September 4, 2022, 10:48am
1
I’m trying to setup the following Grocy shell command as a shell script that I can run as a service:
curl -X 'POST' 'http://homeassistant.local:8888/api/stock/products/1/consume' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'GROCY-API-KEY: redacted' -d '{"amount": 3,"transaction_type": "consume","spoiled": false}'
The command is from the Grocy REST-API and works perfectly in the terminal. However, when I try to save it as a shell command as follows I get the error: “incomplete explicit mapping pair, a key node is missed ”
shell_command:
grocy_consume_item_shell_4: "curl -X 'POST' 'http://homeassistant.local:8888/api/stock/products/1/consume' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'GROCY-API-KEY: redacted' -d '{"amount": 3,"transaction_type": "consume","spoiled": false}'"
I’m pretty sure it has something to do with the quotes this part but I can’t say for sure:
'{"amount": 3,"transaction_type": "consume","spoiled": false}'"
Any ideas?
mirekmal
(Mirek Malinowski)
September 4, 2022, 12:50pm
2
First you do not need to enclose command in double quote. Make it just:
shell_command:
grocy_consume_item_shell_4: curl -X 'POST' 'http://homeassistant.local:8888/api/stock/products/1/consume' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'GROCY-API-KEY: redacted' -d '{"amount": 3,"transaction_type": "consume","spoiled": false}'
and check if this helps…
nukeman
(nukeman)
September 4, 2022, 1:58pm
3
mirekmal:
curl -X 'POST' 'http://homeassistant.local:8888/api/stock/products/1/consume' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'GROCY-API-KEY: redacted' -d '{"amount": 3,"transaction_type": "consume","spoiled": false}'
Thanks for the suggestion. Unfortunately, I still get the same error.
When I run the code in an online yaml checker I get the following error:
Error : incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 2, column 119:
... k/products/1/consume' -H 'accept: application/json' -H 'Content- ...
^
Line : undefined undefined
nukeman
(nukeman)
September 4, 2022, 6:34pm
4
Found a solution here .
In case someone else is having the same problems this worked:
shell_command:
grocy_consume_item: "curl -X POST http://{{server_ip}}:9283/api/stock/products/{{product_id}}/consume -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'GROCY-API-KEY: {{grocy_key}}' -H 'cache-control: no-cache' -d '{ \"amount\": {{amount}}, \"transaction_type\": \"consume\", \"spoiled\": false }'"
le_top
September 4, 2022, 8:37pm
5
A good method is to use:
Both are tools that you can install using pip.
nukeman
(nukeman)
September 5, 2022, 7:28am
6
Is it possible to run these on RPi4 with HA?
le_top
September 5, 2022, 7:42am
7
I do not see why not. I can do it on a NUC using HAOS.
This is how I configured the ‘Terminal & SSH’ Addon:
authorized_keys:
- >-
ssh-rsa
AAAAB...
name@host
password: ""
apks:
- screen
- logrotate
- sqlite
- py3-pip
server:
tcp_forwarding: false
That makes pip available, do then just do pip install yamllint
pip install yamlfix
.
The only drawback is that you have to run that after each ‘Terminal + SSH’ restart. (The installation could be automated by adding something smart to .bash_profile. (I already share my bash setup - maybe I’ll add something smart to install the packages in a requirements.txt
somewhere only after restart or requirements.txt updates ).
le_top
September 5, 2022, 8:27am
8
I updated my bash setup to install the python packages listed in requirement.txt
that is in the same directory as the real .bash_profile
.