How to configure value_template to extract data from JSON array without name

Hi,
I would appreciate help with configuring a REST full sensor to extract multiple sensors from one REST call using templates.
I can extract any value, e.g. temperatur from the first element of the array with below configuration.

However struggle to figure out how I can access any attribute of the second element of the array.
For example the value for JSON Path $.[?(@.etagenname=="OG")].raeume[?(@.name=="Bad")].temperatur

Here is my configuration

sensor:
  - platform: rest
    resource: http://192.168.2.3/get/json/v1/1/temps
    scan_interval: 60
    name: temperatur_sensor
    value_template: 'OK'
    json_attributes:
      - temperature
      - raeume
  - platform: template
    sensors:
      wohnzimmer_ist_temperatur_neu:
        device_class: temperature
        unit_of_measurement: "Ā°C"
        value_template: "{{ states.sensor.temperatur_sensor.attributes.raeume[0].temperatur|round(2) }}"

which returns 17.73 as desired.

My JSON looks like below:

[
    {
        "etagenname": "DG",
        "id": 1,
        "raeume": [
            {
                "total_offset": 0.2,
                "solltemperatur": 12,
                "temperatur": 17.725490196078432,
                "name": "Bad"
            },
            {
                "total_offset": 0.2,
                "solltemperatur": 18,
                "temperatur": 19.137254901960784,
                "name": "Lena"
            }
        ]
    },
    {
        "etagenname": "OG",
        "id": 2,
        "raeume": [
            {
                "total_offset": -0.11529411764705755,
                "solltemperatur": 19.9,
                "temperatur": 16.764705882352942,
                "name": "Bad"
            },
            {
                "total_offset": 0.08,
                "solltemperatur": 16,
                "temperatur": 18.352941176470587,
                "name": "Schlafzimmer"
            }
        ]
    }
]
1 Like

Hmm. I would jump on Discord and ask the devs if the RESTfull sensor supports a JSON array at the top level. Possibly it only grabs the first element.

If not the only suggestion I would have is to retrieve the raw data and load the array into an object then process that, or maybe do it with Node Red.

You can use top level arrays.

Use this tool to get the path to the data you want. Just replace x with value_json

https://jsonpathfinder.com/

You can get all the temperature sensors with the one rest call using the new rest integration rather than the rest sensor platform. No template sensors required:

rest:
  - resource: http://192.168.2.3/get/json/v1/1/temps
    scan_interval: 60
    sensor:
      - name: "DG Bad" #change this to what you want
        value_template: "{{ value_json[0].raeume[0].temperatur }}"
        device_class: temperature
        unit_of_measurement: "Ā°C"
      - name: "DG Lena" #change this to what you want
        value_template: "{{ value_json[0].raeume[1].temperatur }}"
        device_class: temperature
        unit_of_measurement: "Ā°C"
      - name: "OG Bad" #change this to what you want
        value_template: "{{ value_json[1].raeume[0].temperatur }}"
        device_class: temperature
        unit_of_measurement: "Ā°C"
      - name: "OG Schlafzimmer" #change this to what you want
        value_template: "{{ value_json[1].raeume[1].temperatur }}"
        device_class: temperature
        unit_of_measurement: "Ā°C"
3 Likes

Ah - makes sense when you see it done that way.

Thanks for the tip.

This is working, reading the documentation and posts here in the community I however got the impression that using the template sensor is the way how extracting multiple sensors from one REST call should be done.
Could you share a bit of light for a HA green-horn on the difference between the two approaches?
Will your sample extract the sensor values from a single rest call or will a rest call per sensor be initiated?

Thatā€™s the way it was done until the rest integration was introduced. You can still do it that way but itā€™s more work and less efficient.

Thanks for the clarification, sounds great!

is there a way to use a filter to find the index. like raeme[?ā€˜nameā€™=ā€˜Badā€™] instead of raeume[1] or raeume[2]

sincearly
Fredrik

1 Like

Apologies for the hijack but this looks like the same issue that I am trying to solve though I cant seem to get it working using the solution from Post #3.

I too have an unlabelled JSON top level that looks like this;

[
	{
		"releaseDate": "2023-03-05",
		"mediaItem": {
			"id": 11,
			"title": "The Last of Us",
			"releaseDate": "2023-01-15",
			"slug": "the-last-of-us-2023",
			"mediaType": "tv",
			"seen": true
		},
		"episode": {
			"id": 240,
			"title": "When We Are in Need",
			"episodeNumber": 8,
			"seasonNumber": 1,
			"releaseDate": "2023-03-05",
			"seen": true,
			"isSpecialEpisode": false
		}
	},
	{
		"releaseDate": "2023-03-08",
		"mediaItem": {
			"id": 33,
			"title": "The Mandalorian",
			"releaseDate": "2019-11-12",
			"slug": "the-mandalorian-2019",
			"mediaType": "tv",
			"seen": true
		},
		"episode": {
			"id": 267,
			"title": "Chapter 18",
			"episodeNumber": 2,
			"seasonNumber": 3,
			"releaseDate": "2023-03-08",
			"seen": false,
			"isSpecialEpisode": false
		}
	}
]

and my config looks like thisā€¦

rest:
  - resource: http://resource url (Produced the above JSON)
    scan_interval: 60
    sensor:
      - name: "upcoming_ep1"
        value_template: "{{ value_json[0].releaseDate }}"
      - name: "upcoming_ep2"
        value_template: "{{ value_json[1].releaseDate }}"

I am only trying to fetch the release date currently as that seemed a simple place to start as itā€™s a basic entry rather than being a further nested entry but even that is not working. In the Developer > Sates tab, I canā€™t even find the ā€œupcoming_ep1ā€ or ā€œep2ā€ entities. Iā€™ve checked configuration and restarted HA and still nothing.

Any ideas what Iā€™ve missed? sure its something simple.

Hi,
if you want to get the release date for the episode, you would need to modify your value_template like below:

rest:
  - resource: http://resource url (Produced the above JSON)
    scan_interval: 60
    sensor:
      - name: "upcoming_ep1"
        value_template: "{{ value_json[0].episode.releaseDate }}"
      - name: "upcoming_ep2"
        value_template: "{{ value_json[1].episode.releaseDate }}"

Must be something in the logs. Your sensor configuration looks good and the template is correct (@urmel ā€” there is a releaseDate as well as an episode.releaseDate). Make sure you only have one top-level rest: declaration.

Did you ever managed to get this working?
Trying expressions always gives me value_template parsing errors

Itā€™s possible. Paste some JSON (properly formatted please) and explain which value you want to extract.

Thank you for offering help, i just pasted the whole JSON result to pastebin as it contains lots of data :wink:
MontaApp - Pastebin.com
My current try is this JSONPath:

$[?(@.type == "dc")].pricings.public.pricing_entries[?(@.type == "fixed_kwh")].amount

So IĀ“m trying to get only Items with type dc, then going down the path to only fixed_kwh and want to finally get the price / kwh.

This expression works on JSONPath Online Evaluator but is not working in HA.

Also this returns the price three times and i havent found a way to just return it once but this might be fixed later on with piping the value to average() or so.

Hope you can shed some light :wink:

I think so, depends what output you want. You get three prices because there are three prices.

I put this in the template editor (warning: very long first line, which is your PasteBin data minified onto a single line):

{% set value_json = [{"id":3674571,"is_in_charge_point_group":true,"charge_point_group_id":511166,"identifier":"a4462982-223d-11ef-8e85-5e8087b286f5","name":"CHARGE-V - Station 1 - AC - DK*MON*E3674571","operator_name":"Charge-V: Operator.VSP 32 GmbH & Co. KG","location":"47.923851,11.488915","static_map_url":null,"address1":"St2070","address2":"Egling","address3":null,"address":"St2070, Egling, 82544, Egling, Germany","timezone":"Europe/Busingen","city":"Egling","zip":"82544","note":null,"visibility":"public","type":"ac","max_kw":22,"current_max":null,"state":"available","available":true,"integration_count":1,"deleted":false,"placeholder":false,"chat_active":false,"team_id":821679,"has_cable":true,"has_auth_tokens":true,"max_kw_label":"22 kW","type_label":"AC","active":true,"stability_score":82.3,"avg_kw":8.12,"operator_is_roaming":false,"connector_label":"Type 2","show_pickup":true,"pin":{"color":"green","type":"single","number":null,"colors":null},"max_reservation_min":null,"blocked_until":null,"smart_queue_id":null,"fair_priced":null,"payment_terminal":false,"pubnub_channel":null,"master_pricing_type_dynamic":false,"detect_cable":false,"cable_plugged_in":false,"can_smart_charge":false,"solar_charge_enabled":false,"auto_charge":false,"team_plan_is_enterprise":false,"charging_pricing_type":"price","integration_banner_type":null,"connectors":[{"id":2,"identifier":"type2","icon_url":"https://monta.imgix.net/connector_icons/8515c9b0-70d4-11ef-a3c0-67cd23159c48","name":"Type 2"}],"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricings":{"public_label":"0,57 EUR/kWh","user_label":"0,57 EUR/kWh","public":{"label":"0,57 EUR/kWh","reservation_per_min":0.1045,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"user":{"label":"0,57 EUR/kWh","reservation_per_min":0.1045,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"team":null,"team_member":null,"country_area_id":17},"peak_hour":null,"sponsor_status":null},{"id":3674572,"is_in_charge_point_group":true,"charge_point_group_id":511166,"identifier":"b4135182-223d-11ef-a33a-5e8087b286f5","name":"CHARGE-V - Station 1 - DC - DK*MON*E3674572","operator_name":"Charge-V: Operator.VSP 32 GmbH & Co. KG","location":"47.923851,11.488915","static_map_url":null,"address1":"St2070","address2":"Egling","address3":null,"address":"St2070, Egling, 82544, Egling, Germany","timezone":"Europe/Busingen","city":"Egling","zip":"82544","note":null,"visibility":"public","type":"dc","max_kw":160,"current_max":null,"state":"available","available":true,"integration_count":1,"deleted":false,"placeholder":false,"chat_active":false,"team_id":821679,"has_cable":true,"has_auth_tokens":true,"max_kw_label":"160 kW","type_label":"DC","active":true,"stability_score":70.81,"avg_kw":58.02,"operator_is_roaming":false,"connector_label":"CCS","show_pickup":true,"pin":{"color":"green","type":"single","number":null,"colors":null},"max_reservation_min":null,"blocked_until":null,"smart_queue_id":null,"fair_priced":null,"payment_terminal":false,"pubnub_channel":null,"master_pricing_type_dynamic":false,"detect_cable":false,"cable_plugged_in":false,"can_smart_charge":false,"solar_charge_enabled":false,"auto_charge":false,"team_plan_is_enterprise":false,"charging_pricing_type":"price","integration_banner_type":null,"connectors":[{"id":3,"identifier":"ccs","icon_url":"https://monta.imgix.net/connector_icons/9fb79140-70d4-11ef-b9a7-7d9a9c6ec71d","name":"CCS"}],"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricings":{"public_label":"0,57 EUR/kWh","user_label":"0,57 EUR/kWh","public":{"label":"0,57 EUR/kWh","reservation_per_min":0.76,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"user":{"label":"0,57 EUR/kWh","reservation_per_min":0.76,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"team":null,"team_member":null,"country_area_id":17},"peak_hour":null,"sponsor_status":null},{"id":3674573,"is_in_charge_point_group":true,"charge_point_group_id":511166,"identifier":"c46ac0f6-223d-11ef-b7c7-c2b7369d758b","name":"CHARGE-V - Station 2 - AC - DK*MON*E3674573","operator_name":"Charge-V: Operator.VSP 32 GmbH & Co. KG","location":"47.923851,11.488915","static_map_url":null,"address1":"St2070","address2":"Egling","address3":null,"address":"St2070, Egling, 82544, Egling, Germany","timezone":"Europe/Busingen","city":"Egling","zip":"82544","note":null,"visibility":"public","type":"ac","max_kw":22,"current_max":null,"state":"available","available":true,"integration_count":1,"deleted":false,"placeholder":false,"chat_active":false,"team_id":821679,"has_cable":true,"has_auth_tokens":true,"max_kw_label":"22 kW","type_label":"AC","active":true,"stability_score":88.62,"avg_kw":7.08,"operator_is_roaming":false,"connector_label":"Type 2","show_pickup":true,"pin":{"color":"green","type":"single","number":null,"colors":null},"max_reservation_min":null,"blocked_until":null,"smart_queue_id":null,"fair_priced":null,"payment_terminal":false,"pubnub_channel":null,"master_pricing_type_dynamic":false,"detect_cable":false,"cable_plugged_in":false,"can_smart_charge":false,"solar_charge_enabled":false,"auto_charge":false,"team_plan_is_enterprise":false,"charging_pricing_type":"price","integration_banner_type":null,"connectors":[{"id":2,"identifier":"type2","icon_url":"https://monta.imgix.net/connector_icons/8515c9b0-70d4-11ef-a3c0-67cd23159c48","name":"Type 2"}],"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricings":{"public_label":"0,57 EUR/kWh","user_label":"0,57 EUR/kWh","public":{"label":"0,57 EUR/kWh","reservation_per_min":0.1045,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"user":{"label":"0,57 EUR/kWh","reservation_per_min":0.1045,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"team":null,"team_member":null,"country_area_id":17},"peak_hour":null,"sponsor_status":null},{"id":3674576,"is_in_charge_point_group":true,"charge_point_group_id":511166,"identifier":"d3fa0482-223d-11ef-b9d3-16445b8c7a11","name":"CHARGE-V - Station 2 - DC - DK*MON*E3674576","operator_name":"Charge-V: Operator.VSP 32 GmbH & Co. KG","location":"47.923851,11.488915","static_map_url":null,"address1":"St2070","address2":"Egling","address3":null,"address":"St2070, Egling, 82544, Egling, Germany","timezone":"Europe/Busingen","city":"Egling","zip":"82544","note":null,"visibility":"public","type":"dc","max_kw":160,"current_max":null,"state":"available","available":true,"integration_count":1,"deleted":false,"placeholder":false,"chat_active":false,"team_id":821679,"has_cable":true,"has_auth_tokens":true,"max_kw_label":"160 kW","type_label":"DC","active":true,"stability_score":60.52,"avg_kw":51.93,"operator_is_roaming":false,"connector_label":"CCS","show_pickup":true,"pin":{"color":"green","type":"single","number":null,"colors":null},"max_reservation_min":null,"blocked_until":null,"smart_queue_id":null,"fair_priced":null,"payment_terminal":false,"pubnub_channel":null,"master_pricing_type_dynamic":false,"detect_cable":false,"cable_plugged_in":false,"can_smart_charge":false,"solar_charge_enabled":false,"auto_charge":false,"team_plan_is_enterprise":false,"charging_pricing_type":"price","integration_banner_type":null,"connectors":[{"id":3,"identifier":"ccs","icon_url":"https://monta.imgix.net/connector_icons/9fb79140-70d4-11ef-b9a7-7d9a9c6ec71d","name":"CCS"}],"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricings":{"public_label":"0,57 EUR/kWh","user_label":"0,57 EUR/kWh","public":{"label":"0,57 EUR/kWh","reservation_per_min":0.76,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"user":{"label":"0,57 EUR/kWh","reservation_per_min":0.76,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"team":null,"team_member":null,"country_area_id":17},"peak_hour":null,"sponsor_status":null},{"id":3674577,"is_in_charge_point_group":true,"charge_point_group_id":511166,"identifier":"e325f70e-223d-11ef-905c-721fd9b0be74","name":"CHARGE-V - Station 3 - AC - DK*MON*E3674577","operator_name":"Charge-V: Operator.VSP 32 GmbH & Co. KG","location":"47.923851,11.488915","static_map_url":null,"address1":"St2070","address2":"Egling","address3":null,"address":"St2070, Egling, 82544, Egling, Germany","timezone":"Europe/Busingen","city":"Egling","zip":"82544","note":null,"visibility":"public","type":"ac","max_kw":22,"current_max":null,"state":"available","available":true,"integration_count":1,"deleted":false,"placeholder":false,"chat_active":false,"team_id":821679,"has_cable":true,"has_auth_tokens":true,"max_kw_label":"22 kW","type_label":"AC","active":true,"stability_score":88.92,"avg_kw":8.88,"operator_is_roaming":false,"connector_label":"Type 2","show_pickup":true,"pin":{"color":"green","type":"single","number":null,"colors":null},"max_reservation_min":null,"blocked_until":null,"smart_queue_id":null,"fair_priced":null,"payment_terminal":false,"pubnub_channel":null,"master_pricing_type_dynamic":false,"detect_cable":false,"cable_plugged_in":false,"can_smart_charge":false,"solar_charge_enabled":false,"auto_charge":false,"team_plan_is_enterprise":false,"charging_pricing_type":"price","integration_banner_type":null,"connectors":[{"id":2,"identifier":"type2","icon_url":"https://monta.imgix.net/connector_icons/8515c9b0-70d4-11ef-a3c0-67cd23159c48","name":"Type 2"}],"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricings":{"public_label":"0,57 EUR/kWh","user_label":"0,57 EUR/kWh","public":{"label":"0,57 EUR/kWh","reservation_per_min":0.1045,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"user":{"label":"0,57 EUR/kWh","reservation_per_min":0.1045,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39523625,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"team":null,"team_member":null,"country_area_id":17},"peak_hour":null,"sponsor_status":null},{"id":3674578,"is_in_charge_point_group":true,"charge_point_group_id":511166,"identifier":"f111f35e-223d-11ef-a1ca-3efeea7876f1","name":"CHARGE-V - Station 3 - DC - DK*MON*E3674578","operator_name":"Charge-V: Operator.VSP 32 GmbH & Co. KG","location":"47.923851,11.488915","static_map_url":null,"address1":"St2070","address2":"Egling","address3":null,"address":"St2070, Egling, 82544, Egling, Germany","timezone":"Europe/Busingen","city":"Egling","zip":"82544","note":null,"visibility":"public","type":"dc","max_kw":160,"current_max":null,"state":"available","available":true,"integration_count":1,"deleted":false,"placeholder":false,"chat_active":false,"team_id":821679,"has_cable":true,"has_auth_tokens":true,"max_kw_label":"160 kW","type_label":"DC","active":true,"stability_score":73.21,"avg_kw":46.32,"operator_is_roaming":false,"connector_label":"CCS","show_pickup":true,"pin":{"color":"green","type":"single","number":null,"colors":null},"max_reservation_min":null,"blocked_until":null,"smart_queue_id":null,"fair_priced":null,"payment_terminal":false,"pubnub_channel":null,"master_pricing_type_dynamic":false,"detect_cable":false,"cable_plugged_in":false,"can_smart_charge":false,"solar_charge_enabled":false,"auto_charge":false,"team_plan_is_enterprise":false,"charging_pricing_type":"price","integration_banner_type":null,"connectors":[{"id":3,"identifier":"ccs","icon_url":"https://monta.imgix.net/connector_icons/9fb79140-70d4-11ef-b9a7-7d9a9c6ec71d","name":"CCS"}],"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricings":{"public_label":"0,57 EUR/kWh","user_label":"0,57 EUR/kWh","public":{"label":"0,57 EUR/kWh","reservation_per_min":0.76,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"user":{"label":"0,57 EUR/kWh","reservation_per_min":0.76,"currency":{"id":2,"master":false,"identifier":"eur","name":"Euros","decimals":2,"locale_formatted":false},"pricing_entries":[{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null}],"master_pricing":{"id":39519119,"type":"fixed_kwh","amount":0.57,"label":"0,57 EUR/kWh","description":null,"start_min_after_charging":null,"start_min_after_fully_charged":null,"master":true,"end_at_fully_charged":false,"vat":false,"percentage":100,"amount_min":null,"amount_max":null,"from":null,"to":null,"tariff_id":null,"payload":null,"tariff":null},"promotion_code":null,"dynamic":false,"chart":null,"breakdown":[{"current_fixed_price":0.57,"type":"fixed_kwh","label":null,"base_price":"0,57 EUR/kWh","price":"0,57 EUR/kWh","taxes":[]}]},"team":null,"team_member":null,"country_area_id":17},"peak_hour":null,"sponsor_status":null}] %}
{% set dc_list = value_json|selectattr('type','eq','dc') -%}
{% for dc_item in dc_list -%}
{% set prices = dc_item['pricings']['public']['pricing_entries']|selectattr('type','eq','fixed_kwh') -%}
{{ dc_item['id'] }}: {{ (prices|first)['amount'] }}
{% endfor %}

and got this:

3674572: 0.57
3674576: 0.57
3674578: 0.57

If you just want the first public, fixed-kWh price for the first DC charger, then:

{{ ((value_json|selectattr('type','eq','dc')|first)['pricings']['public']['pricing_entries']|selectattr('type','eq','fixed_kwh')|first)['amount'] }}

will return 0.57 from that data set. Build a RESTful sensor with that as the value_template and you should get your amount.

Most of the hard work is being done by Jinja filters, documented here (which is the same page as the top link on the template editor):

https://jinja.palletsprojects.com/en/latest/templates/#list-of-builtin-filters

Wow, thank you for your detailed explanation and help, jinja is still a miracle for me :wink:
Sadly the sensor now reports unknown and i have no clue on how to further debug

Post your full sensor config, showing how you tried to incorporate my code into your sensor.

Itā€™s possible that your resource might return different results in a browser versus an HA request. Try:

value_template: "{{ value[:250] }}"

to see if youā€™re getting the JSON or an error message.

1 Like

Think this should be mentioned in the docs. Helped me a ton to understand i messed up my headers as i got UNAUTHORIZED message.

1 Like