#Changing the visual output of a API JSON Boolean

17 messages · Page 1 of 1 (latest)

upbeat spear
#

Hey Folks, I am playing around with the Queue-Times API to bring in amusement park data into my Home Assistant dashboards. I have all the data coming in at this point, and dashboards set up to display it, but I have a little quirk I have run into a wall trying to fix.

The API has a boolean for whether a ride is open or closed, and it returns true or false. I want my Dashboards to show Open for true and Closed for false. I seem to be struggling to get that to reflect in an easy way. Secondary note, I have each ride importing as a separate entity for this value, so I would like a way to do this via the configuration.yaml rather than any kind of modifier or automation if possible.

Configuration yaml

       value_template: "{{ value_json['lands'][0]['rides'][11]['name'] }}"
     - name: "Park 60 Coaster 11 Status"
       value_template: "{{ value_json['lands'][0]['rides'][11]['is_open'] }}"
     - name: "Park 60 Coaster 11 Wait Time"
       value_template: "{{ value_json['lands'][0]['rides'][11]['wait_time'] }}" ```

Dashboard yaml


```- type: grid
       cards:
         - type: tile
           entity: sensor.park_60_coaster_0_name
           features_position: bottom
           vertical: false
           name: ' '
         - type: entity
           entity: sensor.park_60_coaster_0_wait_time
           name: ' '
           unit: Minutes
         - type: tile
           entity: sensor.park_60_coaster_0_status
           features_position: bottom
           vertical: false
           name: ' ```

Ignore the mismatched sensor names, they are all identical.


I'm pretty new to API and custom sensors so lemme know what additional information I am neglecting to share.
sweet viper
#

Could you explain further what the result is and how it differs from what you want?

#

At first glance it looks like you're grabbing the status from the json and putting it into the "Park 60 coaster 11 status" correctly

#

I assume this is under a binary_sensor

#

Your first code snippet doesn't give quite enough context

upbeat spear
#

I have the data from this API coming into my dashboard as show in this screenshot. The value is going into "Park 60 coaster 11 status" correct. I want to take the "true" result, and have that reflect as "Open", rather than "true".

Here is hopefully a more complete snippet of the configuration

#Kings Island Coaster Sensors
    - resource: "https://queue-times.com/parks/60/queue_times.json"
      sensor:
      - name: "Park 60 Coaster 0 Name"
        value_template: "{{ value_json['lands'][0]['rides'][0]['name'] }}"
      - name: "Park 60 Coaster 0 Status"
        value_template: "{{ value_json['lands'][0]['rides'][0]['is_open'] }}"
      - name: "Park 60 Coaster 0 Wait Time"
        value_template: "{{ value_json['lands'][0]['rides'][0]['wait_time'] }}"```
sweet viper
#

Ah ok. Well you could just add a conditional in the template that has it return "open" if the actual value is "true", but the cleanest way might be to do this via a binary sensor. Let me look into something

#

Looks like the method of defining it is slightly different

#

Perhaps running, problem, or opening. Practically speaking this will just give you nicer icons and colors on your dashboard

#

Let me know if those docs aren't enough to get you going and I can help further

upbeat spear
# sweet viper Ah ok. Well you could just add a conditional in the template that has it return ...

I did just try Device class, and cannot seem to get that to reflect, although it is coded as a sensor not a binary_sensor, I based it off what I saw here https://www.home-assistant.io/integrations/sensor.rest#configuration-variables

Reading the documentation, I think modifying the template is needed, but I cannot seem to get a working configuration, and I did try a few based on some similar forum posts, but none resulted in success.

sweet viper
#

Yes you need to use that with binary_sensor. I'd worry about getting that set up properly first and once it's working you can reap the benefits by using the device class

#

What about something like this?

binary_sensor:
  - platform: rest
    resource: https://queue-times.com/parks/60/queue_times.json
    name: "Park 60 Coaster 0 Status"
    value_template: "{{ value_json['lands'][0]['rides'][0]['is_open'] }}"
#

I think the sensor is pretty liberal in what it considers to be true/false

#

I think the answer is here: https://www.home-assistant.io/integrations/template/

The sensor is on if the template evaluates as True, yes, on, enable or a positive number. Any other value will render it as off. The actual appearance in the frontend (Open/Closed, Detected/Clear etc) depends on the sensor’s device_class value