I have recently learned that you can define a rest sensor without a value_template to retrieve the raw data (maximum length: 255 characters). Then you can define a template sensor to extract the information you are after.
Something like this may work. The template sensor’s state may require some more fine-tuning and error handling:
I’m not aware of a way to do that. It looks as if this integration will immediately try to interpret the returned data as JSON when you want to put data into attributes.
Some alternatives:
Implement a script outside of Home Assisstant that translates the data into JSON (or just the value you need).
Implement a custom component.
I had a brief look into that door bell’s manual and it appears to support HTTP event push, so you could explore if that would work with Home Assistant’s webhooks which you could use to send a notification or change a sensor value.
After some research and thinking, I built the pyscript.
"""
Service script
"""
import aiohttp
url = "http://192.168.10.199:80/cgi-bin/controller_cgi?action=get&user=nnnnn&pwd=xxxxxxxx"
@service
def AlpTest():
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
global outString
outString = resp.text()
print(resp.status)
aText = outString.split()
for nr, keyValue in enumerate(aText):
if keyValue.startswith("Status"):
outValue = keyValue.split("=")
lcStat = outValue[0].lower()
onOff = ('off','on')
arg2 = "turn_" + onOff[int(outValue[1])]
arg3 = "input_boolean.alp600_" + lcStat
# print("input_boolean" + "#" + arg2 + "#" + arg3)
service.call("input_boolean", arg2, arg3)
I created a helper Input_Boolean for each of the three statuses. The logic works. The required character strings are generated correctly. The problem is the service.call.
The error message comes:
TypeError: Function.service_call() takes 3 positional arguments but 4 were given
I’m a total beginner with Python. So far I’ve only programmed in C and Windows-CMD.
You can find a lot of hints on the net. It’s usually about a function argument “self”. But I don’t understand.
A bit late to the party, but in case anyone is still interested: I had a similar problem and was able to solve it by parsing the “value” variable within the value_template.
Basically what @exxamalte suggests, but not in a separate sensor. Something like:
(this bit of code is not tested, just as an example)
That way you can keep the length of the state under 255 char maximum. It will still generate a “Can’t parse JSON” warning in the logs, but will produce the desired result.