Remove quotes from json values

All states are strings. Only attributes can have other types.

Please share your sensor configuration. You can probably use something like today_at(value_json) along with supplying the correct device class.

Alternatively where are you trying to use this state that is causing issues?

1 Like

I’m retrieving event times from a source. These change daily and I want to not only store these but also use them in automation to send a reminder at the specific time retrieved in the API call.

Post the json and your configuration.

I haven’t done the full thing yet. I’ve only started with “mon”

{"city":"london","date":"2024-05-03","mon":"03:30","tue":"12:00","wed":"17:00","thur":"21:00","fri":"21:30"}


- resource_template: >-
    {% set key = "" %}
    https://www. site.com/api/times/?format=json&key={{ key }}&24hours=true/

  headers:
    Content-Type: "application/json"
  scan_interval: 3600
  sensor:
    - name: "az_event_mon"
      value_template: >-
        "{{ value_json.mon }}"

I get:
az_event_mon → “03:30” with the quotes actually included in the value

The sensor itself will not show the quotes, it will be treated as a string without quotes when you look at it in the UI.

That’s what I find confusing. The UI is showing the quotes?!

because you are using multiline notation and single line notation for yaml.

      value_template: >-
        "{{ value_json.mon }}"

Use one or the other, not both.

mutliline…

      value_template: >-
        {{ value_json.mon }}

or single line

      value_template: "{{ value_json.mon }}"

See

1 Like

Thank you all very much indeed for your help. It’s working fine now.

I noticed that it’s making 5 API calls one for each sensor. Shouldn’t it just be one and the values taken and assigned to each “sensor”?

{"city":"london","date":"2024-05-03","mon":"03:30","tue":"12:00","wed":"17:00","thur":"21:00","fri":"21:30"}


- resource_template: >-
    {% set key = "" %}
    https://www. site.com/api/times/?format=json&key={{ key }}&24hours=true/

  headers:
    Content-Type: "application/json"
  scan_interval: 3600
  sensor:
    - name: "az_event_mon"
      value_template:  "{{ value_json.mon }}"
  sensor:
    - name: "az_event_tue"
      value_template:  "{{ value_json.tue }}"
  sensor:
    - name: "az_event_wed"
      value_template:  "{{ value_json.wed }}"
- resource_template: >-
    {% set key = "" %}
    https://www. site.com/api/times/?format=json&key={{ key }}&24hours=true/

  headers:
    Content-Type: "application/json"
  scan_interval: 3600
  sensor:
    - name: "az_event_mon"
      value_template:  "{{ value_json.mon }}"
    - name: "az_event_tue"
      value_template:  "{{ value_json.tue }}"
    - name: "az_event_wed"
      value_template:  "{{ value_json.wed }}"

Sorry. That’s what I did. I copied the wrong bit.

When I had the word sensor, it only created the az_event_wed

Even with this:

- resource_template: >-
    {% set key = "" %}
    https://www. site.com/api/times/?format=json&key={{ key }}&24hours=true/

  headers:
    Content-Type: "application/json"
  scan_interval: 3600
  sensor:
    - name: "az_event_mon"
      value_template:  "{{ value_json.mon }}"
    - name: "az_event_tue"
      value_template:  "{{ value_json.tue }}"
    - name: "az_event_wed"
      value_template:  "{{ value_json.wed }}"

I’m still seeing 5 API calls in the logs

that will only make 1 call, how are you certain it’s making 5?

You are right. There is only one entry for:
DEBUG (MainThread) [homeassistant.components.rest]

and 5 for
DEBUG (MainThread) [homeassistant.components.rest.data]

I completely missed the .data bit in the log

Thank you once again.

1 Like

@petro Is there a way to manually trigger the API call and updating the sensors using an automation?

See: How to set a custom scan_interval

In your case because the integration is not set up via the UI just set a really long scan interval (years) in the YAML config.

Then do the automation bit.

Note: It will still poll once when you restart home assistant.

Many thanks @tom_l , I can’t see the RESTful integration under Devices. If I try to add it through the UI I get a message that this cannot be done through the UI.

Which is why I said:

Yes but you linked to another post on how to use automation to trigger manual updates and the first thing in the post talked about enabling polling for updates for the integration which I thought was required in order to allow the automation to trigger the update. Is that not the case?

thats not the case

I’ve told you this three times now.

In your case because the integration is not set up via the UI ignore the first bit about polling in the UI.

Instead just set a really long scan interval (years) in the YAML config.

Then do the automation bit in that post.

And take note of the exception about restarts I mentioned.

Got it. Many thanks. It’s working perfectly now.

Thank you both