dubocr / homebridge-tahoma

Homebridge plugin for TaHoma, Connexoon, Cozytouch, Energeasy Connect.
Apache License 2.0
131 stars 42 forks source link

ExteriorHeatingSystem is a switch #209

Closed Silkjaer closed 3 years ago

Silkjaer commented 3 years ago

Hi,

ExteriorHeatingSystem works perfectly but is appearing as a Switch. Our awning exterior heater can be adjusted in heating level, so it would be awesome to have it appear as a light instead, that can be adjusted in brightness (heating level).

Let me know what information is needed and what I can do to supply it.

Thanks!

Silkjaer commented 3 years ago

I added a "PatioHeater.js" to the services folder and edited Lightbulb to support external heaters (Solamagic heater with Somfy IO control). Then i used the config to "forceType" the heater to "PatioHeater".

var Log, Service, Characteristic;
var AbstractService = require('./AbstractService');
var { Command, ExecutionState } = require('../overkiz-api');

class PatioHeater extends AbstractService {
    constructor (homebridge, log, device, config) {
        super(homebridge, log, device);
        Log = log;
        Service = homebridge.hap.Service;
        Characteristic = homebridge.hap.Characteristic;

        this.service = new Service.Lightbulb(device.getName());
        this.onState = this.service.getCharacteristic(Characteristic.On);
        this.onState.on('set', this.setOn.bind(this));

        if(this.device.widget.includes('DimmerExteriorHeating')) {
            this.levelState = this.service.addCharacteristic(Characteristic.Brightness);
            this.levelState.on('set', this.setLevel.bind(this));
        }
    }

    /**
    * Triggered when Homekit try to modify the Characteristic.On
    **/
    setOn(value, callback) {
        var commands = [];

        switch(this.device.widget) {
            case 'DimmerExteriorHeating':
                if(value == 1) { callback(); break; } // Ignore 'on' command for DimmerExteriorHeating as homekit send 'on' + 'brightness'
            default:
                commands.push(new Command(value ? 'on' : 'off'));
            break;
        }
        if(commands.length) {
            this.device.executeCommand(commands, function(status, error, data) {}.bind(this), callback);
        }
    }

    /**
    * Triggered when Homekit try to modify the Characteristic.Brightness
    **/
    setLevel(value, callback) {
        var commands = new Command('setLevel', 100 - value);

        if(commands) {
            this.device.executeCommand(commands, function(status, error, data) {}.bind(this), callback);
        }
    }

    onStateUpdate(name, value) {
        var levelState = null;

        switch(name) {
            case 'core:LevelState':
                levelState = 100 - value; // reverse
            break;
        }

        if (this.levelState != null && levelState != null) {
            this.levelState.updateValue(levelState);
            if(levelState == 0) {
                this.onState.updateValue(0);
            }
            else {
                this.onState.updateValue(1);
            }
        }
    }
}

module.exports = PatioHeater
gongevangen commented 3 years ago

I have the exact same problem, but I don't fully understand you solution.

  1. "PatioHeater.js" do I create a new file in services with the name "PatioHeater.js" and copy the code above into it? Does it need to be required in an other file?
  2. Can you show the lines you added to Lightbulb.js and where to add them.
  3. What exactly did you enter in the "forceType" line?
Silkjaer commented 3 years ago

1) Yes

2) I didn't make changes to Lightbulb, but I based the above code on the Lightbulb implementation.

3) In the config, add this snippet with the name of your heater, to force the type from the default "Switch" to the new type "PatioHeater".

"forceType": {
        "Name of the heater": "PatioHeater"
},
gongevangen commented 3 years ago

How can I copy PatioHeater.js to the service folder. My homebridge is running on a Rasberry PI and I am trying to use the command scp PatioHeater.js pi@192.168.87.33:/usr/local/lib/node_modules/homebridge-tahoma/services from MacOS, but then it askes for a password and the one I use for HomeBridge does not work.

Silkjaer commented 3 years ago

Do you ssh to the pi? Then you need to use the same username and password for scp.

gongevangen commented 3 years ago

I fixed it by using scp PatioHeater.js pi@192.168.87.33: to get it to the PI and then use sudo cp PatioHeater.js /usr/local/lib/node_modules/homebridge-tahoma/services/ to copy it to services. Now it works real fine - should be standard part of the npm module.

dubocr commented 3 years ago

Hi,

Could you please expose your config with following steps to let me know implements your changes in next releases.


  1. Execute operations from official app (TaHoma/Cozytouch/etc.) then execute same operation from Homekit
  2. Report your config by browsing https://dev.duboc.pro/tahoma
  3. Search issues with title corresponding to your device widget name (see picture below). If no opened issue, rename your issue with this widget name.
  4. Provide your bridge last 4 digits (number visible as SETUP-XXXX-XXXX-XXXX at step 2.) Widget

Thank you.