sibartlett / homebridge-wink3

Homebridge plugin for wink.com
https://sibartlett.github.io/homebridge-wink3
ISC License
54 stars 20 forks source link

Outlets and Switches and Fans - Binary Switches #57

Closed mriksman closed 7 years ago

mriksman commented 7 years ago

Only the Outlink supports consumption in Wink. But you could have a binary_switch that is connected to an outlet. In this case, the device wouldn't have consumption. Because of this, there needs to be a manual way to set a binary_switch as an outlet.

I have modified the const declarations up the top to;

const isFan = (state, device, config) =>        config.fan_ids.indexOf(device.object_id) !== -1;

const isOutlet = (state, device, config) =>     config.outlet_ids.indexOf(device.object_id) !== -1 ||
                                                state.consumption !== undefined;

const isSwitch = (state, device, config) =>     config.switch_ids.indexOf(device.object_id) !== -1;

const isLightBulb = (state, device, config) =>  !isFan(state, device, config) &&
                                                !isOutlet(state, device, config) &&
                                                !isSwitch(state, device, config);

So an Outlet can be manually defined, or it can look for the consumption property. It also needs a slight modification to the 'Outlet in Use' property;

        characteristic: Characteristic.OutletInUse,
//        get: state => state.consumption > 0.1
        get: state => {
                if (state.consumption == undefined)
                        return state.consumption > 0.1;
                else
                        return state.powered;
        }

If a binary_switch is defined as a Service.Outlet, then you can change the type within Home to;

If a binary_switch is defined as a Service.Switch, then you can change the type within Home to;

Which means that, you don't really need to identify a fan. You could just identify it as an Outlet or a Switch, and modify the type within the Home app.

mriksman commented 7 years ago

Also needed to add the fix for the leakSMART valve which detects as a binary_switch, but uses opened, not powered.

const isValve = (state, device, config) =>      state.opened != undefined;

const isLightBulb = (state, device, config) =>  !isFan(state, device, config) &&
                                                !isOutlet(state, device, config) &&
                                                !isSwitch(state, device, config) &&
                                                !isValve(state, device, config);
    }, {
      service: Service.Switch,
      supported: isValve,
      characteristics: [{
        characteristic: Characteristic.On,
        get: state => state.opened,
        set: value => ({ opened: !!value })
      }]
sibartlett commented 7 years ago

I think all these fixes are now included in 1.7.0