Create sensor from a Curl command

HI,

Other than direct api calls, i have a hub i can only reach through curl api calls.
I can extract all info (and hope to create separate template sensors afterwards) by giving this curl command:

curl -X POST -d '{"seq":1, "method":"objmgr_get_objects_init"}' http://192.168.xxx.xxx/iungo/api_request

How can i create a sensor (rest, or jsonrest maybe?) from this command? do i need to use a shell_command? but how to get the result in the sensor

The other (json)rest sensors i have have a full url as resource, which in this case isn’t available onfortunately.

or is this the way:
sensor:
- platform: command_line
command: curl -X POST -d ‘{“seq”:1, “method”:“objmgr_get_objects_init”}’ http://192.168.xxx.xxx/iungo/api_request
name: Iungo Sensor

A bit afraid to run the system down if this is incorrect, so rather hear from the community first…

Maybe you can help?
Thanks,
Marius

The command_line sensor should work for you.
You will need to put quotes around your command

command: "curl -X POST -d ‘{“seq”:1, “method”:“objmgr_get_objects_init”}’ http://192.168.xxx.xxx/iungo/api_request"

And you may need to use the value_template depending what is returned from the curl command.

You can set a scan_interval to determine how often you want the sensor to update ( in seconds ).

scan_interval: 30

Don’t be scared to try. I doubt you can do any damage by making http requests.

hmm, something’s amiss:

- platform: command_line
  command: "curl -X POST -d '{"seq":1, "method":"objmgr_get_objects_init"}' http://192.168.xxx.xxx/iungo/api_request"
  name: Iungo Sensor

2018-02-05 08:39:58 ERROR (SyncWorker_0) [homeassistant.util.yaml] while parsing a block mapping
  in "/config/sensors/sensor_template.yaml", line 6, column 3
expected <block end>, but found '<scalar>'
  in "/config/sensors/sensor_template.yaml", line 7, column 32
2018-02-05 08:39:58 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/sensors/sensor_template.yaml", line 6, column 3
expected <block end>, but found '<scalar>'
  in "/config/sensors/sensor_template.yaml", line 7, column 32

yamllint :

You have got the " and the ’ wrong. Don’t use " inside your statement it interfere with the " you need for the whole command.

tried the following because of the ’ ’ and " " issue like i did with several other sensor and switches:

- platform: command_line
  command: >-
    curl -X POST -d '{"seq":1, "method":"objmgr_get_objects_init"}' http://192.168.xxx.xxx/iungo/api_request
  name: Iungo Sensor

This gives no syntax error, rather a result error, state being over 255 characters. (which is correct, it reads the full Zwave Hub…)

Invalid state encountered for entity id: sensor.iungo_sensor. State max length is 255 characters.

hi!
our posts crossed.
added the below to the test setup:

- platform: command_line
  command: "curl -X POST -d '{'seq':1, 'method':'objmgr_get_objects_init'}' http://192.168.xxx.xxx/iungo/api_request"
  name: Iungo Sensor cl

Thanks!
Marius

You’ll need to use the value_template: to extract the value you want so you don’t run into the 255 character limit.

sure, thanks
I ws trying to create ‘mother’ sensor, of which all those value_template sensors were to be derived…
Mother is too big :wink:

with my Hue sensors and SolarEdge panel sensors (using rest or jsonrest) this works fine.
Ive ried to create these too, but no such luck yet.

Trying to create a sensor for a water monitor and my postman request works great, but I may be missing something obvious as I can’t make it work with the command_line:

  - platform: command_line
    command:
      "curl -X POST -H 'Content-type: application/json' -d '
        { 
	        'email':'MYEMAIL',
	        'password': 'MYPASS',
	        'procedure': 'get_api_downloads'
        }' https://novamail.biz/pipe_guardian_php_api/PipeGuardianApi.php"

any suggestion please?