staromeste / homebridge-http-advanced-accessory

Supports all devices on HomeBridge Platform / Bridges devices to http
Apache License 2.0
65 stars 22 forks source link

Temperature values in fahrenheit #37

Closed ravedoglv closed 2 years ago

ravedoglv commented 2 years ago

I successfully managed to poll a network device for its temp. However, the units values are fahrenheit but apparently my readout in HomeKit shows as Celsius. Any ideas on how to correct the value?

ravedoglv commented 2 years ago

I seem to have solved it.

So here was my original code:

{
    "accessory": "HttpAdvancedAccessory",
    "service": "TemperatureSensor",
    "name": "Air Temp",
    "forceRefreshDelay": 5,
    "debug": false,
    "urls": {
        "getCurrentTemperature": {
            "url": "http://192.168.1.156/state.xml",
            "mappers": [{
                    "type": "xpath",
                    "parameters": {
                        "xpath": "//oneWireSensor1/text()",
                        "index": 0
                    }
                }
            ]
        }
    }
}

so the device was returning the value in Fahrenheit, which is what I wanted. However, this plugin was publishing this number as a Celsius number and HomeKit is in Fahrenheit.

So I changed the code to add an eval and did some math

{
    "accessory": "HttpAdvancedAccessory",
    "service": "TemperatureSensor",
    "name": "Air Temp",
    "forceRefreshDelay": 5,
    "debug": false,
    "urls": {
        "getCurrentTemperature": {
            "url": "http://192.168.1.156/state.xml",
            "mappers": [{
                    "type": "xpath",
                    "parameters": {
                        "xpath": "//oneWireSensor1/text()",
                        "index": 0
                    }
                },
                {
                    "type": "eval",
                    "parameters": {
                        "expression": "value = (value - 32) / 1.8"
                    }
                }
            ]
        }
    }
}

now, the number in HomeKit is correct.