RESTful Sensor with non-json list of values?

Hi,
I want to read the status of my doorbell ALP600 as a rest sensor. The Http-Get returns a list of pairs of values.

  - platform: rest
    name: alp600_status3
    resource: http://192.168.10.199/cgi-bin/controller_cgi?action=get&user=nnnn&pwd=xxxxxx
    authentication: basic
    value_template: '{{ value_json.Status3 }}'
    scan_interval: 30 

That will not do! It’s neither xml nor json.

The Return of Http-Get looks like this:


Type=3n
Output1=open
Delay1=4
Status1=0
CloseByCall1=close
CloseByFace1=close
CloseByNight1=close
CloseByMdNight1=close
Output2=open
Delay2=1
Status2=0
CloseByCall2=close
CloseByFace2=close
CloseByNight2=close
CloseByMdNight2=close
Output3=open
Delay3=0
Status3=0
CloseByCall3=close
CloseByFace3=close
CloseByNight3=close
CloseByMdNight3=close
PlaySound=close


how to parse that elegantly. I am interested in the values “Status3”.
Thanks in advance

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:

sensor:
  - platform: rest
    name: alp600_status3_raw
    resource: http://192.168.10.199/cgi-bin/controller_cgi?action=get&user=nnnn&pwd=xxxxxx

template:
  - sensor:
      - name: Status3
        state: "{{ ( states('sensor.alp600_status3_raw') | regex_findall(find='Status3=(.*)\n', ignorecase=False) )[0] }}"

Thank you very much for your hints.
I just tested it.
Unfortunately it does not work. In the log I find the following message:

homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.alp600_http_raw. State max length is 255 characters.

I tested the following variants:

  - platform: rest
    name: alp600_http_raw
    resource: http://192.168.10.199/cgi-bin/controller_cgi?action=get&user=nnnn&pwd=xxxxx
    authentication: basic
    scan_interval: 30 

  - platform: rest
    name: alp600_http_raw
    resource: http://192.168.10.199/cgi-bin/controller_cgi?action=get&user=nnnn&pwd=xxxxx
    authentication: basic
    value_template: "{{ value }}"
    scan_interval: 30 

The limit of 255 characters applies to ‘state’, but not to ‘attribute’.
Is there a trick how to put non-json/non-xml in an attribute?

Thanks in advance

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.

Thank you very much for your hints.

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.

Please help.
Thanks in advance