Command Line switch/sensor & Curl error


I just installed the image of Hassio on a raspberry, but when I created a switch with a command_line it tells me continually an error, here is the command used:

  • platform: command_line
    name: Room temperature
    command: “curl -s’ http: // IP: PORT / json.htm? type = devices & rid = 122 ‘| jq -r .result [].’ Data ‘| cut -d’ -f1”
    unit_of_measurement: “° C”
    scan_interval: 30

Do you have any idea where the problem will come from?

How about creating a scrape sensor and use it with a a template switch instead?

Thank you I did not know I will test

I do not understand how to use scrape sensors.
I would like to recover the value of a temperature sensor.

If I open the url "http://IP:PORT/json.htm?type=devices&rid=18"in chrome, here is the result:
“ActTime”: 1515506873,
“ServerTime”: “2018-01-09 15:07:53”,
“Sunrise”: “08:37”,
“Sunset”: “17:11”,
“result”: [
“AddjMulti”: 1.0,
“AddjMulti2”: 1.0,
“AddjValue”: 0.0,
“AddjValue2”: 0.0,
“BatteryLevel”: 78,
“CustomImage”: 0,
“Data”: “18.9 C”,
“Description”: “”,
“Favorite”: 1,
“HardwareID”: 6,
“HardwareName”: “Thermostat”,
“HardwareType”: “Netatmo”,
“HardwareTypeVal”: 54,
“HaveTimeout”: false,
“ID”: “12B4”,
“LastUpdate”: “2018-01-09 15:07:23”,
“Name”: “Salon temperature”,
“Notifications”: “false”,
“PlanID”: “2”,
“PlanIDs”: [2],
“Protected”: false,
“ShowNotifications”: true,
“SignalLevel”: 10,
“SubType”: “LaCrosse TX3”,
“Temp”: 18.899999999999999,
“Timers”: “false”,
“Type”: “Temp”,
“TypeImg”: “temperature”,
“Unit”: 180,
“Used”: 1,
“XOffset”: “341”,
“YOffset”: “341”,
“idx”: “18”
“status”: “OK”,
“title”: “Devices”

I would like to recover the value of “Data” so “18.9 C”

Do you have an article or tutorial that explains how it works?
Thank you.

Ah if your URL returns JSON, you might be better off using the REST platform?

  - platform: rest
    resource: http://IP:PORT/json.htm?type=devices&rid=18
    name: Room temperature
    value_template: '{{ value_json.Data }}'

Not played too much with JSON extraction so I think you’ll need to amend '{{ value_json.Data }}' as your Data is under result

I was just trying this but without success it returns a null value:

Temperature Salon ° C

It does not indicate the temperature.


  • platform: rest
    resource: http://IP:PORT/json.htm?type=devices&rid=18
    name: Température Salon
    value_template: ‘{{ value_json.Data }}’
    unit_of_measurement: °C

Result in the Home Assistant “< >” :
sensor.temperature_salon unit_of_measurement: °C
friendly_name: Température Salon
icon: mdi:thermometer

yes, as I said it won’t work with just {{ value_json.Data }}, you jeed to adjust as Data is under result in the JSON tree…
not sure if it should be {{ value_json.result.Data }} or {{ value_json.result[Data] }} or different.

Thanks again for the help, I managed by writing:

value_template: ‘{{ value_json.result[0].Data }}’

1 Like

Thanks for confirming and providing the format, I’ll keep a note of this for when I pull json data in the future :slight_smile:

@DOESIT Just out of curiosity, is this a Netatmo Thermostat?

If so, why not use the Netatmo Thermostat component? Why re-invent the wheel, ya know!

Yes indeed, he is not here to reinvent the wheel, I simply took an example parmit multiple temperature sensors that I have at home.

It is a Netatmo themostat indeed, the others are cheap sensors.
DANIU 433MHz Station Météo

Quick question, what do you use to receive the signal from the cheap sensors?

I use a Rfxcom transceiver.

Thanks.i was hoping you’d say something else. I have one too but it’s a type 1 and doesn’t support that sensor (I realised that after I bought 6 of course)

Ok, I do not know the other models but you have I think, check if there was no update to support this sensor?

Thanks but no. It’s one of the first ones and doesn’t support that sensor :frowning:

I have a new question!:thinking:

So I manage to make the switch work, but I would like to get its status, because if I turn on my switch via my home automation, home-assistant doesn’t know it, so use the "command_state"option.

Here is the command I use to get the status of the switch:“command_state:’ /usr/bin/curl -s “http://IP:PORT/json.htm?type=devices&rid=RID” | jq -r. result[]. Data’”.

It’s not working!
It seems that the returned data must be “0” or “1” and not “On” or “Off”. Do you have any idea how to transform “On” into “0” and “Off” into “1”??

why don’t you adjust your template from:
{{ value_json.result[0].Data }}
{% if value_json.result[0].Data == "On" %} 1 {% else %} 0 {% endif %} ?

I tried this but it doesn’t work:

  command_on: '/usr/bin/curl k- "http://IP:PORT/json.htm?type=command&param=switchlight&idx=IDX&switchcmd=On"'
  command_off: '/usr/bin/curl -k "http://IP:PORT/json.htm?type=command&param=switchlight&idx=IDX&switchcmd=Off"'
   command_state: '/usr/bin/curl -s "http://IP:PORT/json.htm?type=devices&rid=IDX"'
   value_template: '{% if value_json.result[0].Data == "On" %} 1 {% else %} 0 {% endif %}'

Does you log state anything?
The syntax appears to be correct I can’t test the full command of course as I don’t have any value_json.result[0].Data to play with…