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

Ability to use mappers in URL templates #8

Open TimofeyK opened 5 years ago

TimofeyK commented 5 years ago

I am trying to configure a new Daikin Airbase BRP15B61 aircon controller as a thermostat. Due to its very poor API I need to set both TargetHeatingCoolingState and TargetTemperature in one URL

I am not able to do that because can't map state values back to URL parameters when using URL template

Below is excerpt of my attempted config

"getTargetHeatingCoolingState": {
                    "url": "http://10.0.1.30/skyfi/aircon/get_control_info",
                    "mappers": [
                        {
                            "type": "regex",
                            "parameters": {
                                "regexp": "(pow=0)",
                                "capture": "1"
                            }
                        },
                        {
                            "type": "regex",
                            "parameters": {
                                "regexp": "mode=(\\d)",
                                "capture": "1"
                            }
                        },
                        {
                            "type": "static",
                            "parameters": {
                                "mapping": {
                                    "0": "3",
                                    "1": "1",
                                    "2": "2",
                                    "pow=0": "0"
                                }
                            }
                        }
                    ]
                },
                "setTargetHeatingCoolingState": {
                    "url": "http://10.0.1.30/skyfi/aircon/set_control_info{value}&stemp=${state.getTargetTemperature}&f_airside=0&f_rate=5&shum=0&f_dir=0",
                    "mappers": [
                        {
                            "type": "static",
                            "parameters": {
                                "mapping": {
                                    "0": "?pow=0&mode=2",
                                    "1": "?pow=1&mode=1",
                                    "2": "?pow=1&mode=2",
                                    "3": "?pow=1&mode=0"
                                }
                            }
                        }
                    ]
                },
                "setTargetTemperature": {
                    "url": "http://10.0.1.30/skyfi/aircon/set_control_info${state.getTargetHeatingCoolingState}&stemp={value}&f_airside=0&f_rate=5&shum=0&f_dir=0"

                    }

Feature request: ability to use URL templates in mapping to convert HomeKit state values returned by the template to URL parameters

staromeste commented 5 years ago

If the mapping is "0": "3", "1": "1", "2": "2" I think you can do something like in the URL ${state.getTargetHeatingCoolingState == 3 ? 0 : state.getTargetHeatingCoolingState}

That means that if TargetHeatingCoolingState in HK is 3 replace it with 0 otherwise use that value.

Guido

On Wed, 30 Jan 2019 at 05:07, TimofeyK notifications@github.com wrote:

I am trying to configure a new Daikin Airbase BRP15B61 aircon controller as a thermostat. Due to its very poor API I need to set both TargetHeatingCoolingState and TargetTemperature in one URL

I am not able to do that because can't map state values back to URL parameters when using URL template

Below is excerpt of my attempted config

-

getTargetHeatingCoolingState is similar to your readme example and I can map Daikin's pow=x&mode=y parameters to HomeKit state 0-3 values

in setTargetHeatingCoolingState I can use URL template for state.getTargetTemperature and map state values back to Daikin's parameters

but for setTargetTemperature I can't do that because state.getTargetHeatingCoolingState returns 0-3 HomeKit values. I can't map them back to Daikin's parameters using {value} because the value represents temperature. Essentially I need a resulting value from setTargetHeatingCoolingState

"getTargetHeatingCoolingState": { "url": "http://10.0.1.30/skyfi/aircon/get_control_info", "mappers": [ { "type": "regex", "parameters": { "regexp": "(pow=0)", "capture": "1" } }, { "type": "regex", "parameters": { "regexp": "mode=(\d)", "capture": "1" } }, { "type": "static", "parameters": { "mapping": { "0": "3", "1": "1", "2": "2", "pow=0": "0" } } } ] }, "setTargetHeatingCoolingState": { "url": "http://10.0.1.30/skyfi/aircon/set_control_info{value}&stemp=${state.getTargetTemperature}&f_airside=0&f_rate=5&shum=0&f_dir=0", "mappers": [ { "type": "static", "parameters": { "mapping": { "0": "?pow=0&mode=2", "1": "?pow=1&mode=1", "2": "?pow=1&mode=2", "3": "?pow=1&mode=0" } } } ] }, "setTargetTemperature": { "url": "http://10.0.1.30/skyfi/aircon/set_control_info${state.getTargetHeatingCoolingState}&stemp={value}&f_airside=0&f_rate=5&shum=0&f_dir=0"

                }

Feature request: ability to use URL templates in mapping to convert HomeKit state values returned by the template to URL parameters

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/staromeste/homebridge-http-advanced-accessory/issues/8, or mute the thread https://github.com/notifications/unsubscribe-auth/AEL9MTQyD9Pdlq5uK9Z30PUdbSWUBItLks5vIRqRgaJpZM4aZajV .

TimofeyK commented 5 years ago

Mappings I need are from the HK state (e.g. 1) to the URL parameter that needs to be included in the URL and sent to the aircon (e.g. ?pow=1&mode=2)

                                    "0": "?pow=0&mode=2",
                                    "1": "?pow=1&mode=1",
                                    "2": "?pow=1&mode=2",
                                    "3": "?pow=1&mode=0"

Do you mean that evaluations like ${state.getTargetHeatingCoolingState == 1 ? "?pow=1&mode=1"} can be used in URLs? But how can I use the full mapping as above?

TimofeyK commented 5 years ago

It would be easier if HK supported Thermostat as On/Off switch and mode selector (heat/cool), this is how my aircon is designed. But HK exposes "states" as off/cool/heat/auto so I have to combine Power parameter with Mode parameter: