Supereg / homebridge-http-temperature-sensor

Http temperature sensor for Homebridge: https://github.com/homebridge/homebridge
ISC License
31 stars 18 forks source link

Taking temperature from the body #9

Closed pierzcha closed 5 years ago

pierzcha commented 5 years ago

Hello, I have a small problem with taking the temperature from my device. I am trying to configure it so that it downloads data from the blebox sensor, after http I get such data {"tempSensor":{"sensors":[{"type":"temperature","id":0,"value":2118,"trend":2,"state":2,"elapsedTimeS":1055}]}} I try to get the temperature with a regular expression but it doesn't work for me, what am I doing wrong? My configuration:

{"accessory": "HTTP-TEMPERATURE", "name": "Temperature Sensor", "statusPattern": "/((?<=\"value\":)[0-9]{2})/", "getUrl": "http://192.168.1.204/api/tempsensor/state" }

Supereg commented 5 years ago

Any error messages which are produced by this plugin? try a pattern like this "statusPattern": "\"value\":([0-9]{2})". Note that I removed the slashes at the beginning and the end since those are not needed. The plugin extracts the value contained in the first group (configurable). As you just want the number you just need to but the number matching in brackets so only the numbers get extracted.

pierzcha commented 5 years ago

Any error messages which are produced by this plugin? try a pattern like this "statusPattern": "\"value\":([0-9]{2})". Note that I removed the slashes at the beginning and the end since those are not needed. The plugin extracts the value contained in the first group (configurable). As you just want the number you just need to but the number matching in brackets so only the numbers get extracted.

Thanks for answer, when I try my regax I got: [Temperature Sensor] getTemperature() error occurred while extracting temperature from body: Pattern didn't match (value: '{"tempSensor":{"sensors":[{"type":"temperature","id":0,"value":2118,"trend":2,"state":2,"elapsedTimeS":2209}]}}', pattern: '/\/((?<="value":)[0-9]{2})\//')

When I changed to your suggestion it worked :) Thank you very much

It would be possible to add one or two additional digits after the decimal point, e.g. 21,1 or 21.18 ??

Supereg commented 5 years ago

... Pattern didn't match ... Yeah one problem were the leading and trailing slash. And I see now this mistake is also present in the README 😅

In theory yes but in praxis no. The plugin will happily accept those numbers if they are formatted correctly (so there is a decimal point in the input). And the will round it to 0.5 steps (as HomeKit expects it). But it cannot handle it in the format you are currently supplying it (without a decimal point)

pierzcha commented 5 years ago

... Pattern didn't match ... Yeah one problem were the leading and trailing slash. And I see now this mistake is also present in the README 😅

In theory yes but in praxis no. The plugin will happily accept those numbers if they are formatted correctly (so there is a decimal point in the input). And the will round it to 0.5 steps (as HomeKit expects it). But it cannot handle it in the format you are currently supplying it (without a decimal point)

I changed my index.js file and formatted the data there so that it would display correctly. Thanks for the help.