Work with api Kangaroo security, how save new token in "memory" (rest api)?

I do integration with kangaroo temperature sensor. I have all requests, and this work, but its first programing for HA.

I try work with rest api in configuration.yaml, all work good 1h, next need update token

My code from configuration.yaml:

rest:
  - resource: URL_FOR_REFRESH_TOKEN
    headers: 
      User-Agent: FirebaseAuth.iOS/10.2.0 com.kangaroo.security/10.1 iPhone/15.4.1 hw/iPhone10_3
      X-Firebase-Locale: en-US
      X-Client-Version: iOS/FirebaseSDK/10.2.0/FirebaseCore-iOS
      X-Firebase-Client: ******
      X-Ios-Bundle-Identifier: com.kangaroo.security
      X-Firebase-GMPID: '*****'
    payload: '{ "grantType": "refresh_token", "refreshToken": "XXXXXX" }'
    method: POST
    scan_interval: 3600
    THIS IS NEW TOKEN (FROM JSON): "{{value_json.access_token}}"
    
  - resource: URL_FOR_SENSOR_1
    headers: 
      User-Agent: KangarooSecurity/19447 CFNetwork/1331.0.7 Darwin/21.4.0
      X-OS-Version: 15.4.1
      X-OS: iOS
      X-App-Language: en_US
      X-App-Build: 19447
      X-Authorization: HERE NEED TOKEN FROM FIRST REQUEST
      X-App-Version: 10.1
    method: GET
    scan_interval: 3600
    sensor:
      - name : "Bedroom 1 Temperature"
        value_template: "{{(value_json.lastTemperature )}}"
        unit_of_measurement: "°C"
        device_class: temperature
      - name: "Bedroom 1 Humidity"
        value_template: "{{ (value_json.lastHumidity) }}"
        unit_of_measurement: '%'
        device_class: humidity
        
  - resource: URL_FOR_SENSOR_2
    headers: 
      User-Agent: KangarooSecurity/19447 CFNetwork/1331.0.7 Darwin/21.4.0
      X-OS-Version: 15.4.1
      X-OS: iOS
      X-App-Language: en_US
      X-App-Build: 19447
      X-Authorization:  HERE NEED TOKEN FROM FIRST REQUEST
      X-App-Version: 10.1
    method: GET
    scan_interval: 3600
    sensor:
      - name : "Bedroom 2 Temperature"
        value_template: "{{(value_json.lastTemperature )}}"
        unit_of_measurement: "°C"
        device_class: temperature
      - name: "Bedroom 2 Humidity"
        value_template: "{{ (value_json.lastHumidity) }}"
        unit_of_measurement: '%'
        device_class: humidity 

This code need start every 1h (same like sensor share info to server), and show all on dashboard

I can write all this in python, but i dont know how start python script by time in HA and show info after requests on dushboard

1 Like

Regarding the issue of the token update, it is important to note that the maximum character limit for an entity is 255. To work around this, you can use an attribute with a key and then reference it in another REST request. For example, you can add the following to your first request:

value_template: '{{value_json.token_type}}'
json_attributes:
  - id_token

Then, in your second request, replace the line X-Authorization: HERE NEED TOKEN FROM FIRST REQUEST with {{ state_attr('sensor.kangaroo_key', 'id_token') }}.

This should allow you to obtain the updated token and use it in your subsequent requests. I hope this helps, and please let me know if you have any further questions."