Rest Sensor, Value template not as expected

Well… I’ve created some REST Sensors successfully, but now I’m playing with the value templates and I appear to be stuck. The idea is to find out if I can charge at the public EV charger at home (the first UID in the JSON) which is parking for EV only. The second port (second UID) is not parking for EV only - so the spot isn’t guaranteed.

The Sensor “works”, but creating a value template for it…

I’m trying to replicate this as follows in Developer Tools, Template:

{% if (value_json['evses'][0]['status'], 'Available') %}
  Guaranteed to charge
{% elif (value_json['evses'][0]['status'], 'Occupied') %}
  Not Guaranteed to charge  
{% elif (value_json['evses'][1]['status'], 'Available') %}
  Possibility to charge    
{% else %}
  No charger available
{% endif %}

I’ve defined value_json as:

{% set value_json = {
    "uid": 2745958,
    "externalId": "NLALLEGO002725",
    "coordinates": {
        "latitude": 51.730447,
        "longitude": 4.965855
    },
    "operatorName": "Allego",
    "address": {
        "streetAndNumber": "Molenplantsoen 36",
        "postalCode": "4271 AH",
        "city": "Dussen",
        "country": "NLD"
    },
    "accessibility": {
        "status": "Unspecified",
        "remark": "",
        "statusV2": "Public"
    },
    "accessibilityV2": {
        "status": "Public"
    },
    "evses": [
        {
            "uid": 1363583,
            "externalId": "NLALLEGO0027251",
            "evseId": "NL*ALL*EGO0027251",
            "status": "Occupied",
            "connectors": [
                {
                    "uid": 1299149,
                    "externalId": "1",
                    "connectorType": "Type2",
                    "electricalProperties": {
                        "powerType": "AC3Phase",
                        "voltage": 230,
                        "amperage": 16,
                        "maxElectricPower": 11
                    },
                    "fixedCable": false,
                    "tariff": {
                        "perKWh": 0.59,
                        "currency": "EUR",
                        "updated": "2023-06-27T16:20:43Z",
                        "updatedBy": "Default",
                        "structure": "Flat"
                    },
                    "updated": "2022-05-13T01:03:20Z",
                    "updatedBy": "Feed",
                    "betaTariffV2": {
                        "perKWh": 0.59,
                        "currency": "EUR",
                        "updated": "2023-06-27T16:20:43Z",
                        "updatedBy": "Default",
                        "structure": "Flat"
                    }
                }
            ],
            "authorizationMethods": [
                "RFIDToken"
            ],
            "physicalReference": "NL*ALL*EGO0027251",
            "updated": "2023-06-27T12:06:43Z"
        },
        {
            "uid": 1363584,
            "externalId": "NLALLEGO0027252",
            "evseId": "NL*ALL*EGO0027252",
            "status": "Available",
            "connectors": [
                {
                    "uid": 1299150,
                    "externalId": "1",
                    "connectorType": "Type2",
                    "electricalProperties": {
                        "powerType": "AC3Phase",
                        "voltage": 230,
                        "amperage": 16,
                        "maxElectricPower": 11
                    },
                    "fixedCable": false,
                    "tariff": {
                        "perKWh": 0.59,
                        "currency": "EUR",
                        "updated": "2023-06-27T16:20:43Z",
                        "updatedBy": "Default",
                        "structure": "Flat"
                    },
                    "updated": "2022-05-13T01:03:20Z",
                    "updatedBy": "Feed",
                    "betaTariffV2": {
                        "perKWh": 0.59,
                        "currency": "EUR",
                        "updated": "2023-06-27T16:20:43Z",
                        "updatedBy": "Default",
                        "structure": "Flat"
                    }
                }
            ],
            "authorizationMethods": [
                "RFIDToken"
            ],
            "physicalReference": "NL*ALL*EGO0027252",
            "updated": "2023-06-27T10:35:55Z"
        }
    ]
} %}

As you can see, the first UID is ‘Occupied’, but the result of my template value still indicates “Guaranteed to charge”. I must be doing something massively wrong, anyone care to help?

{% if value_json['evses'][0]['status'] == 'Available' %}

… and likewise for the others.

Your attempt was evaluating a tuple (like a list) ('Occupied', 'Available'), which evaluates as true if it’s not empty.

1 Like

Awesome, thanks!