Restful sensor for garage

Hi,

I’m trying to set sensor with variable access token as the the token change every 2 days, it never works, but if I set it manually it will work.

I’m new to home assistant so please bare with me😀

Here is my sensor.yaml

  • platform: rest
    icon: mdi:garage-variant
    name: “Garage Door Status”
    resource: https://api.wyzecam.com/app/v2/device/get_property_list
    method: POST
    headers:
    Content-Type: application/json
    payload: >
    {
    “sc”: “xxxx”,
    “sv”: “xxxx”,
    “app_ver”: “com.hualai___2.47.0.373”,
    “ts”: 1702266071435,
    “access_token”: “{{state_attr(‘sensor.garage_door_token’, ‘data’)[‘access_token’] | default(‘’)}}”,
    “phone_id”: “xxxxx-3d9d-4cd8-9465-xxxxx”,
    “app_name”: “com.hualai”,
    “device_mac”: “xxxxxxxxxxx”,
    “device_model”: “WYZE_CAKP2JFUS”,
    “target_pid_list”: [“P1049”, “P1050”, “P1056”]
    }
    value_template: >
    {% set data = value_json.data %}
    {% if data and data.property_list %}
    {% set garage_door_status = data.property_list | selectattr(“pid”, “eq”, “P1056”) | map(attribute=“value”) | first %}
    {% if garage_door_status == “1” %}
    Open
    {% elif garage_door_status == “2” or garage_door_status == “0” %}
    Closed
    {% else %}
    Unknown
    {% endif %}
    {% else %}
    Unknown
    {% endif %}