Rest sensor setup by template

Hi! I am trying to get some sensor from my Samsung washer machine.
I can get the status below by Postman but how do I setup a template so i can get as sensor for example the section machineState?

{
    "completionTime": {
        "value": "2024-12-22T10:51:29Z",
        "timestamp": "2024-12-22T09:37:29.870Z"
    },
    "machineState": {
        "value": "run",
        "timestamp": "2024-12-22T09:37:32.613Z"
    },
    "washerJobState": {
        "value": "wash",
        "timestamp": "2024-12-22T09:37:58.355Z"
    },
    "supportedMachineStates": {
        "value": [
            "stop",
            "run",
            "pause"
        ],
        "timestamp": "2024-12-22T09:37:18.330Z"
    }
}

This is a handy tool for finding json data paths: https://jsonpathfinder.com/ Paste your data on the left, drill down to the value you want on the right. At the top of the right hand column replace “x” with “value_json” in your value template.

How to configure restful sensors:

e.g.

configuration.yaml

rest:
  - authentication: basic
    username: "admin" # optional
    password: "password" # optional
    scan_interval: 60
    resource: http://your.resource.url.or.ip.address.here # change this
    sensor:
      - name: "Washer Job State"
        value_template: "{{ value_json.washerJobState.value }}"
      - name: "Washer Machine State"
        value_template: "{{ value_json.machineState.value }}"

By using the rest integration both sensors will be updated from one call to the resource. The rest sensor platform by contrast would have to call the resource twice.

Thank you for providing correctly formatted data, it really helps with creating an example.

1 Like

Thanks! That was the trick! Now I only need to figure out how to change values from English to Swedish e.g ‘Stop’ to ‘Klar’ :slight_smile:

I solved it by this,

- name: "Tvättmaskin status"
        value_template: >
          {% if value_json.machineState.value == "run" %}
            Tvättar
          {% elif value_json.machineState.value == "stop" %}
            Klar
          {% endif %}