RSSi Sensor

Hello! I want to make the RSSI value sensor devices connected to the Wi-Fi router. My router is Keenetic giga 3.
Technical support Keenetic suggest to use the following address: http://192.168.1.1/rci/show/associations to parsiong RSSI value from connected devices.
The problem is that the authorization is through js script.
I tried use this script in the node.js and it works, but i have no idea how make a sensor in HA.

It have JSON and js

Blockquote
{
“name”: “rci-auth”,
“version”: “0.0.1”,
“description”: “”,
“main”: “rci-auth.js”,
“scripts”: {
“run”: “node rci-auth.js”
},
“author”: “eralde”,
“license”: “WTFPL”,
“dependencies”: {
“axios”: “^0.18.0”,
“js-md5”: “^0.7.3”,
“jssha”: “^2.3.1”
}
}

Summary

const axios = require(‘axios’);
const md5 = require(‘js-md5’);
const jsSHA = require(‘jssha’);

const KEENETIC_IP = ‘192.168.0.2’;
const LOGIN = ‘';
const PASSWORD = '
*’;

const AUTH_URL = http://${KEENETIC_IP}/auth;
const RCI_URL_PREFIX = http://${KEENETIC_IP}/rci;

const getSha256Hash = (text) => {
const shaObj = new jsSHA(‘SHA-256’, ‘TEXT’);
shaObj.update(text);
return shaObj.getHash(‘HEX’);
};

const getMd5HashArg = (login, realm, password) => ${login}:${realm}:${password};

const getCryptedPass = (login, password, token, realm) => {
const md5Arg = getMd5HashArg(login, realm, password);
const md5Hash = md5(md5Arg);

return getSha256Hash(token + md5Hash);
}

const authPromise = new Promise((resolve, reject) => {
axios.get(AUTH_URL)
.then((res) => {
console.log(‘NO PASSWORD’);
resolve();
})
.catch((err) => {
const headers = err.response.headers;
const token = headers[‘x-ndm-challenge’];
const realm = headers[‘x-ndm-realm’];

  // DEBUG OUTPUT
  console.log(`TOKEN=<${token}>`);
  console.log(`REALM=<${realm}>`);
  console.log(headers);

  const cookies = headers['set-cookie'][0].split(';');

  // DEBUG OUTPUT
  console.log(`COOKIES=<${cookies}`);

  axios({
      method: 'post',
      url: AUTH_URL,
      headers: {
          Cookie: cookies[0]
      },
      data: {
        login: LOGIN,
        password: getCryptedPass(LOGIN, PASSWORD, token, realm)
      }
    })
    .then((res) => {
      console.log('AUTHORIZED!');
      resolve(cookies[0]);
    })
    .catch((err) => {
      console.log('ERROR', err);
      reject();
    });
});

});

authPromise.then((cookie) => {
let headers = {};

if (cookie) {
headers.Cookie = cookie;
}

axios({
method: ‘get’,
url: ${RCI_URL_PREFIX}/show/associations,
headers: headers
})
.then(requestObj => {
console.log(requestObj.data);
});
})

And result from node.js
js1
P.S.: sorry for my english…

Template sensor can pull data from json to a ha sensor :blush:

As an example i use this to get a value from a zigbee device

    sensors:
      aqara_sov_lq:
        value_template: "{{ state_attr('sensor.0x00158d0002f8a251_battery', 'linkquality') }}"
        friendly_name: 'Aqara Soverom'

The sensor named sensor.0x00158d0002f8a251_battery has many values published signal strength among others. So i just pull that value to a new sensor. aqara_sov_lq is the name of the new sensor.

Thanks for the answer. This is not applicable in this case. First I need authorize in using an authorization script. As soon as JSON data are received, they can already be parsing with template sensor.

do you mind posting the code for that sensor?