Curl command to update variable on Fibaro HC3

Hi there. I’m looking into a curl which I need to put to a Fibaro HC3. It will be used for updating a global variable. In an OSX terminal the following is working;

curl -X PUT "http://10.0.0.108/api/globalVariables/Floor_home" -H  "accept: application/json" -H  "Content-Type: application/json" -H  "X-Fibaro-Version: 2" -H  "Accept-language: en" -H  "Authorization: Basic  ccccccccccccc" -d "{\"name\":\"name\",\"isEnum\":true,\"readOnly\":true,\"value\":\"1\"}

The variable actually gets updated from “0” to “1”.

I have been trying to set this up using an automation. But I cannot get it to work. The variable will no be updated when the automation is triggered. I cannot see any errors…

Is there someone who can help me out?

In configuration.yaml I have put;

shell_command:
  home_away: "curl -X PUT {{ url }} -H '{{ ac }}' -H '{{ CT }}' -H '{{ XF }}' -H '{{ Al }}' -H '{{ Au }}' -d '{{ data }}'"

In the automation as “Actions”

service: shell_command.home_away
data:
  url: '"http://10.0.0.108/api/globalVariables/Floor_home"'
  ac: '"accept: application/json"'
  CT: '"Content-Type: application/json"'
  XF: '"X-Fibaro-Version: 2"'
  Al: '"Accept-language: en"'
  Au: '"Authorization: Basic  ccccccccccccc"'
  data: '"{\"name\":\"name\",\"isEnum\":true,\"readOnly\":true,\"value\":\"0\"}"'

Thx! Cheers,

I feel like you should just use a restful command rather than a shell command. Shell command is a little funky with templates…it will evaluate inside a sandbox so you can’t accidentally do nefarious things.

rest commands are essentialy curl commands.

rest_command:
  home_away:
    url: "http://10.0.0.108/api/globalVariables/Floor_home"
    method: PUT
    headers:
      Content-Type: "application/json"
      accept: "application/json"
      X-Fibaro_version: 2
      Accept-language: en
      authorization: "Basic cccccccc"
    payload: '{"name":"name","isEnum":true,"readOnly":true,"value":"{{value}}"}'
      
service: rest_command.home_away
data:
  value: 1
service: rest_command.home_away
data:
  value: 0

Thx! Jocnnor, that did the trick only had to adjust quotes;

in configuration.yaml

rest_command:
  home_away:
    url: "http://10.0.0.108/api/globalVariables/Floor_home"
    method: PUT
    headers:
      Content-Type: "application/json"
      accept: "application/json"
      X-Fibaro_version: "2"
      Accept-language: "en"
      authorization: "Basic cccccccc"
    payload: '{"name":"name","isEnum":true,"readOnly":true,"value":"{{value}}"}'

and in the automation:

service: rest_command.home_away
data:
  value: 1

and

service: rest_command.home_away
data:
  value: 0
1 Like