Write return value from Rest API to file

I’m a beginner at HA and trying to learn and expand my knowledge by developing some real world examples.

I currently have a call which sends values from Zwave sensors to an API receiver on an IIS server.

The API receiver on the IIS server is configured to return a unique identifier for each value that is sent. I would like to collect this value and write it to a log file (so I can check to make sure all values are recorded successfully.

The rest command in my configuration.yaml is very simple:

rest_command:
#make a rest api call with a variable value i.e. lux
  ccc_send_value:
    url: "https://xxxxxx/Push/Data/{{ url_param }}{{url_value}}"
    method: GET

This is called from automations set up against each sensor:

  action:
  - data_template:
      url_param: ?R=V&A=0&M=FIBDOORTEMP&D=
      url_value: '{{ states("sensor.fibaro_system_fgdw002_door_opening_sensor_2_temperature")
        }}'
    service: rest_command.ccc_send_value

I’ve had a look through the documentation and played around with my code, but haven’t got any closer. The data is received by the IIS server, but I am not sure how to collect the return value and write it into a file. This really isn’t my area of expertise and so I was wondering if someone might be able to give me a simple example that a noobie like me might be able to follow?

Use a rest sensor instead of a rest command.

Then there is a file notification service you can use.

Set up the the file notify service:

notify:
  - name: save_to_file
    platform: file
    filename: <FILENAME and PATH here>

Then use it as you would any other notification service, i.e. send a message to it. It will be store in the file you specified.

trigger:
  platform: state
  entity_id: sensor.your_sensor_here #triggers on any change of the sensor
action:
  service: notify.save_to_file
  data:
    message: "{{ states('sensor.your_sensor_here') }}"

Hi Tom,

Thanks for that, I’ll look to get the log writing set up - my main problem is how I would collect the response ID from the API call?

You can’t. Commands are one way. Out. So…

Actually, lots of rest sensors, since you cant pass parameters to the sensor.