I want to create a command_line sensor that uses a CURL call. If I go to the HA Terminal, I can sent the command and get a JSON returned,
$ curl -X GET https://api.carbonintensity.org.uk/regional/postcode/LE16 -H 'Accept: application/js'
#{"data":[{"regionid":9,"dnoregion":"WPD East Midlands","shortname":"East Midlands","postcode":"LE16","data":[{"from":"2025-06-16T07:00Z","to":"2025-06-16T07:30Z","intensity":{"forecast":206,"index":"high"},"generationmix":[{"fuel":"biomass","perc":27.9},{"fuel":"coal","perc":0},{"fuel":"imports","perc":3.5},{"fuel":"gas","perc":43.8},{"fuel":"nuclear","perc":0.6},{"fuel":"other","perc":0},{"fuel":"hydro","perc":0},{"fuel":"solar","perc":13.4},{"fuel":"wind","perc":10.7}]}]}]}[core-ssh ~]
But I just can’t figure how to translate this into YAML
- sensor:
command: "curl -X GET https://api.carbonintensity.org.uk/regional/postcode/LE16 -H 'Accept: application/json'"
name: Carbon Intensity UK
unique_id: carbonintensityuk
#unit_of_measurement: string (Optional) Defines the unit of measurement of the sensor, if any.
value_template: '{{ value_json.data.date.intensity.forecast | float | round(0) }}''
#string (Optional) Defines a template to extract a value from the payload.
#availability template (Optional, default: true) Defines a template to get the available state of the entity. If the template either fails to render or returns True, "1", "true", "yes", "on", "enable", or a non-zero number, the entity will be available. If the template returns any other value, the entity will be unavailable. If not configured, the entity will always be available. Note that string comparisons are not case sensitive; "TrUe" and "yEs" are allowed.
#device_class device_class (Optional) Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the unit_of_measurement.
#state_class string (Optional) The state_class of the sensor. This will display the value based on the Number Format defined in the user profile.
scan_interval integer: 300
I’d be happy to thrash around for a bit, but I can’t work out how to debug this.