I would like to read information from an old automation card, which controls four relays and reads the status of four doors. Not having found any possible integration with HA (chip 18F family from Microchip), I think it is easier to try to read this information from the web page interface, at http://ip-address/status.xml, thet gives me this result:
The value that interests me is refer to btn0 (dn or up), but I really don’t know if it is possible to extract it and make it become a value inside HA. Could you help me to do it?
Thank you .
use a command line sensor to read the webpage data then use a regex to extract the data you want.
you just have to set the scan interval correctly to catch the updated data.
here is an example of a sensor based on a sensor I use to extract my camera motion sensor status (http address and regex modified for yours) that updates the sensor every 3 seconds:
Hi @finity ,
thank you for your suggestion. I wasted half a day just to solve a first error that was reported from HA:
while scanning a double-quoted scalar in “/config/configuration.yaml”, line 39, column 21 found unknown escape character ‘S’ in “/config/configuration.yaml”, line 39, column 62
In practice it was enough to invert the single quotes with the double quotes and the problem was solved:
value_template: '{{ value | regex_findall_index("<btn0>(\S+)</btn0>")}}'
Now I just can’t get the string I need (‘dn’ or ‘up’), but it always returns “unknowed”. Also I could not find clear explanations related to regex, so even in attempts I have not found solutions. If you can solve the code or indicate a site with clear explanations about regex, I would be grateful.
value_template: '{{ value | regex_findall_index("<btn0>(\S+)</btn0>")}}'
I wrote this:
value_template: "{{ value | regex_findall_index('<btn0> (\S+) </btn0>')}}"
notice the spaces before and after (\S+)
regex is kind of tricky.
there is some explanation in the HA docs but there is also a site you can use to test the regex patterns called “regex101”. I would post a link but my google is acting up right now.
may be true (I don’t use either of them very often so no real extensive experience to know definitively either way for my uses) but it is another tool in the tool box.
I don’t see anything out of the ordinary, other than the template error doesn’t match your configured value_template field. {{ value_json.converted.CGI_Result.motionDetectAlarm }} vs {{ value_json.CGI_Result.motionDetectAlarm }}
if I use it as a string result and I use this as the template it extracts it fine and the result is ‘1’ as expected (might be able to use a better template but whipped it up quickly as proof of concept):
{{ value.split('>')[6].split('<')[0] }}
it doesn’t seem to be an issue with the rest sensor per se but in the code to do the conversion from xml to json that seems to be failing for some reason.
As I said I put the result into an xml to json converter and it didn’t complain so it has to be valid xml.