amlinger / homebridge-telldus-tdtool

A Homebridge plugin for Tellstick without Live, interfaced with the CLI tool tdtool.
21 stars 11 forks source link

Use config.json for configuring sensors. #31

Closed jannylund closed 7 years ago

jannylund commented 7 years ago

This PR adds the functionality to use config file as documented in https://github.com/amlinger/homebridge-telldus-tdtool/issues/30

"platforms": [
        {
            "name": "TellstickDuo",
            "platform": "Telldus-TD-Tool",
            "sensors": [
                {
                    "id": 114,
                    "model": "temperaturehumidity",
                    "name": "Bathroom"
                },
                {
                    "id": 142,
                    "model": "temperature",
                    "name": "Sauna"
                },
                {
                    "id": 74,
                    "model": "temperature",
                    "name": "Freezer"
                }
            ]
        }
    ]

Each sensor need to have two mandatory members, id (to identify it uniquely) and model (since we don't know that at this stage).

jannylund commented 7 years ago

Updated PR to fix the case where the sensor() method return undefined which renders homebridge dead. This was actually a bug that could happen previously as well, if telldusd was restarted after homebridge.

pkempe commented 7 years ago

Using the below config.json, I can't get the filter to work. Sensors which are not listed in the config still show up, e.g. "Thermometer 1", even though the tdtool output for that particular sensor is

type=sensor protocol=mandolyn model=temperaturehumidity id=1 temperature=-50.0 humidity=0 time=2016-10-22 08:01:13 age=222858.

    "platforms": [
    {
     "platform" : "Telldus-TD-Tool",
     "name" : "Telldus-TD-Tool",
         "sensors": [
                {
                    "id": 14,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 21,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 22,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 13,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 238,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 11,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 12,
                    "model": "temperaturehumidity"
                },
                {
                    "id": 23,
                    "model": "temperaturehumidity"
                }
            ]
     }
     ]

PS. Do I really need to clear out the accessories and persist folders, change the MAC and pin of Homebridge in config.json in order to test this? Is there a better way?

jannylund commented 7 years ago

@pkempe strange, that should not be the case. With this PR, unnamed sensors should be named "Sensor 14", etc, and nothing related to "Termomether xx" should be visible.

I'm not 100% sure on the need to clear things out of homekit though.

Can you please paste the log you see when starting up homekit with this PR merged?

If this doesn't work, please try installing from https://github.com/jannylund/homebridge-telldus-tdtool/tree/develop (Which is similar, but with all PR's merged)

jannylund commented 7 years ago

@pkempe I confirmed there is no need to clear out anything. Just removing one of these instances from your config and restarting homebridge is enough.

You should see something like this in startup:

[10/25/2016, 12:52:06 AM] [TellstickDuo] Found 6 items of type "sensor" from "config.json".
[10/25/2016, 12:52:06 AM] [TellstickDuo] Initializing platform accessory 'Bastu'...
[10/25/2016, 12:52:06 AM] [TellstickDuo] Initializing platform accessory 'Garderob'...
[10/25/2016, 12:52:06 AM] [TellstickDuo] Initializing platform accessory 'Badrum'...
[10/25/2016, 12:52:06 AM] [TellstickDuo] Initializing platform accessory 'Utomhus'...
[10/25/2016, 12:52:06 AM] [TellstickDuo] Initializing platform accessory 'Garage'...
[10/25/2016, 12:52:06 AM] [TellstickDuo] Initializing platform accessory 'Frysen'...
pkempe commented 7 years ago

Here's there log:

Oct 25 06:35:06 rpi homebridge[10776]: [2016-10-25 06:35:06] [Telldus-TD-Tool] Found 12 items of type "sensor".
Oct 25 06:35:06 rpi homebridge[10776]: [2016-10-25 06:35:06] [Telldus-TD-Tool] Model "1A2D" is not supported, try [selflearning-switch, codeswitch, selflearning-dimmer, humidity, temperature, temperaturehumidity]. If you stillhave not found what you're looking for, submit a pull at https://github.com/amlinger/homebridge-telldus-tdtool
Oct 25 06:35:06 rpi homebridge[10776]: [2016-10-25 06:35:06] [Telldus-TD-Tool] Initializing platform accessory 'Utomhusbrytare'...
Oct 25 06:35:06 rpi homebridge[10776]: [2016-10-25 06:35:06] [Telldus-TD-Tool] [Utomhusbrytare]: getServices called
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Brytare 1'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] [Brytare 1]: getServices called
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Brytare 2'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] [Brytare 2]: getServices called
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 177'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 11'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 14'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 12'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 13'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 21'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 22'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 23'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 1'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 43'...
Oct 25 06:35:07 rpi homebridge[10776]: [2016-10-25 06:35:07] [Telldus-TD-Tool] Initializing platform accessory 'Thermometer 141'...
Oct 25 06:35:07 rpi homebridge[10776]: Scan this code with your HomeKit App on your iOS device to pair with Homebridge:
pkempe commented 7 years ago

Considering the above, it seems I have not correctly installed the PR properly. Isn't git pull origin pull/31/head); npm run build and then copying the dist folder contents all that's required?

jannylund commented 7 years ago

@pkempe yes, I confirmed that it works if I do it that way. (however I run npm install instead, which then calls npm run build.

If you still have issues, maybe try to make a clean clone of this repo. (or simply clone my fork and use the develop branch).

jannylund commented 7 years ago

I think this one is done now. Please merge it if you agree, and I'll rebase https://github.com/amlinger/homebridge-telldus-tdtool/pull/30

amlinger commented 7 years ago

Thanks for submitting this, looks like a good implementation and a good interface to me. Tracking the progress on feedback to config fields on #35.