#REST call with variables, and process the return

1 messages · Page 1 of 1 (latest)

raw kayak
#

I've seen some examples of REST calls that pass a variable out to a service via URL, and others that recieve JSON from a fixed URL. I'm looking to do a phone lookup, with the flow being
When the phone rings :

  • Grab the number (I have this)
  • Package the number into a REST call on the URL
  • Recieve the JSON blob the call returns
  • Do something with that JSON data

It seems like this should be fairly easy, but I haven't seen any code that lets me put variables in the request, and process the return data.

burnt wigeon
#

I am storing call information in JSON format in a text helper (be aware of thr 255 character limit though) with an automation.

{"name": "{{ states.sensor.fritz_box_7590_ax_call_monitor_google.attributes.from_name }}", "number": "{{ states.sensor.fritz_box_7590_ax_call_monitor_google.attributes.from }}", "time": "{{ now().strftime('%H:%M') }}", "date": "{{ now().strftime("%d.%m.%Y") }}"}

In a template sensor I process that data with something like this for the name:

{% set call=(states('input_text.last_call')|from_json) %}
{{ call.name }}