I’m trying to get a REST sensor to work, now after 3 days of searching, I’m turning to the community for help.
I’m from South Africa where we have load shedding on our power and I want to get some values from a website (https://www.poweralert.co.za/#), I’ve looked at the API and from other discussions, someone mentioned a callback JSON. I have never worked with JSON so I’m clueless.
Unfortunately that is not a JSON response. That URL that you have found generates a JavaScript callback function that a website can then use to display the information. The rest sensor won’t work with this.
I just thought about a possible way out, but it’s not really elegant. You could try to extract the JSON by removing the surrounding JavaScript code. This will store the JSON payload as the sensor’s state, and there is a risk: The sensor’s state can only store up to 255 characters, and the response you currently get is very close.
Just beaten to it by @exxamalte, but the above works. Note that the response has a typo in “DeclaredAvailabilty” which briefly caught me out.
The value_template line with the two splits in it is extracting the bit of the response between the brackets, which is then a string that looks like valid JSON.