johnlemonse / homebridge-telldus

36 stars 22 forks source link

Any one got a Door Sensor to work? #61

Open DavidNolander opened 6 years ago

DavidNolander commented 6 years ago

Just bought this:

http://telldus.com/produkt/magnetsensor-telldus-z-wave/

Should work as a switch with ON/OFF commands

Anyone got this to work in Homebridge?

dezral commented 6 years ago

yea but will just be a switch in homekit so no door actions there.. same with motion sensor..

would be nice if there could be more then just temp/hum sensor and on/off switches.. i know telldus don't support a motion sensor as other then on/off and then you via z-wave config set the level of detection that trigger that on/off.. but could a motion sensor be seen in homekit as as actually a motion sensor? i know there a homebridge adding that can do it with things like a pir sensor on a raspberry pi... @mifi ?

but i am loving how well this plugin is already working .. love from here ;-)

mifi commented 6 years ago

should be possible. https://github.com/KhaosT/HAP-NodeJS/blob/master/accessories/MotionSensor_accessory.js

you're saying telldus reports motion sensors the same way as on/off switches? if not I would need to know the json response of a motion sensor. even better a zwave sensor to test with :D

dezral commented 6 years ago

yea in telldus live they do.. if you need to change when a device changes stat then you do it by "edit the devices z-wave config" skaermbillede 2017-11-24 kl 14 19 26 skaermbillede 2017-11-24 kl 14 18 21

433 motion sensor

{ "id": 9, "methods": 3, "name": "Motion Stuen", "state": 2, "statevalue": "", "type": "device" },

z-wave door sensor

{ "id": 17, "methods": 0, "name": "Ford\u00f8r Sensor", "state": 2, "statevalue": "", "type": "device" },

433 mhz door sensor

{ "id": 20, "methods": 3, "name": "Bagd\u00f8r sensor", "state": 2, "statevalue": "", "type": "device" },

is there anything else you need ?

dezral commented 6 years ago

was looking in the code, i don't see any outlet service.. can that be added while we are at it ;-)..

"model": "outlet", or am i totally off? // just so that outlet would be shown as outlet's in homekit...

@DavidNolander have not found any window/door service in the homebridge software...

mifi commented 6 years ago

I implemented outlet and motion-sensor as well as improved models in readme.

You can test it with this:

npm i -g jchnlemon/homebridge-telldus#new-services

Then change your model to motion-sensor or outlet in config.json

For updated readme see: https://github.com/johnlemonse/homebridge-telldus/blob/new-services/README.md#device-models

When confirmed that it's working, i'll merge to master

dezral commented 6 years ago

hi, well the motion sensor does registret in homekit fine it seems, but when telldus say's there are motion ... homekit does not seem to see any triggering or alarm.. don't see anything in the logs either..

I have not checked the outlet model yet.. are not home until tomorrow again.. will check then.

dezral commented 6 years ago

Nov 26 13:21:04 raspberrypi homebridge[3816]: [2017-11-26 13:21:04] [Telldus Liv!e local] [Motion Stuen] Getting state for switch Motion Stuen [on]

i only get a trigger when i start the home app and it ask for data.. and then home app comes with a message.. so it seems that homebridge is not reading telldus and sending it to homekit if im not starting the home app(does not help just being ind the home app)... i have it on local API access.. would remote API do anything different ??

update: Outlet works..

update 2: found this: https://github.com/KhaosT/HAP-NodeJS/issues/382 https://github.com/KhaosT/HAP-NodeJS/issues/497

DavidNolander commented 6 years ago

Using Remote API

I am guessing that the state of all switches are only fetched when the Home App starts?

Is it possible to push states to Homebridge when they change on the Telldus side?

From what I've seen in Home Assistant they can fetch state every 5 seconds, but it would be better if it was on change instead.

dezral commented 6 years ago

it's HAP-NodeJS https://github.com/KhaosT/HAP-NodeJS/blob/master/accessories/MotionSensor_accessory.js as homebridge-tellduq uses that does not support door-window sensor(at least i can't finde support in HAP-NodeJS releases).... homekit does.. i have an legato eve door sensor that works well..

2017-11-26 22:51 GMT+01:00 DavidNolander notifications@github.com:

Regarding the Door Sensor there is Characteristic Type for Door, number 12.

Can have 4 states in Homekit Close (0), Open (1), Closing (2), Opening (3), Stopped (4).

The Telldus Sensor in the API log has 2 states: {"ts":1511731836,"state":1,"stateValue":0,"origin":"Incoming signal","successStatus":0},{"ts":1511731836,"state":2," stateValue":0,"origin":"Incoming signal","successStatus":0}]}

1 = Open 2 = Closed

Don't know if its worth the hassle to add Door and just use those 2 states for Open, Close.

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/johnlemonse/homebridge-telldus/issues/61#issuecomment-347041326, or mute the thread https://github.com/notifications/unsubscribe-auth/AEfF4CG6_7FQu8dgUGe9mi2jt6-ML9BXks5s6d1fgaJpZM4QpjPI .

-- -Harry

mifi commented 6 years ago

State of all devices is fetched when showing devices on iOS. (Open Home app or slide up from below)

I guess we could continously poll telldus API every 5 sec and report this value to homebridge. I'm not sure how happy telldus would be about this though. At least we could do it for local API because then it just goes to your local device which does no harm. If there is a way to listen for events in telldus api it would be even better.

DavidNolander commented 6 years ago

Ok.

How often can you do it local? Maybe an option to set intervall in the config? So default is on showing device.

On Home Assistant the interval can be set. Tried it there.

But even at 5 seconds it feels ”unsmart” so ifk it can be done more often on Local that would be great.

mifi commented 6 years ago

How often, i guess it depends on how many devices you have. but every 5 seconds doesn't sound too bad on local api. does home assistant use telldus live api or local api?

dezral commented 6 years ago

As I read up on telldus/api and HAP-NodeJS/homebridge.. and your code.. it seems it's telldus that does not inform the homebridge-telldus plugin that the motion sensor is triggered... could this be done in a lua script on the telldus znet lite device? that when a motion/door sensor is triggered it contacts homebridge-telldus via (lets say) json on a port?.. i have found other plugins/services that does this..

but your solution could work also, just not optimal ;-) (i know it's telldus that set the limit here).

DavidNolander commented 6 years ago

On Home Assistant i used Live API.

5 seconds between opening a door and light turns on, thats like Forever :)

dezral commented 6 years ago

had a little talk with telldus..

There is a http plugin under development. Unfortunately there is a blocker for it to be released. If you are interested, read more here: https://github.com/scoder/lupa/issues/84 <<

iZac85 commented 6 years ago

To get the correct icon in HomeKit, was quite easy. I just added the following code to index.js:

{
    model: 'contact-sensor',
    definitions: [{ service: Service.ContactSensor, characteristics: [ Characteristic.ContactSensorState, Characteristic.StatusLowBattery ] }],
}

I don't think the StatusLowBattery is implemented since I can't see it in HomeKit. Then I simply added an entry to my config.json to set the device as a contact-sensor:

{
    "local_id": 1,
    "model": "contact-sensor",
    "manufacturer": "Telldus",
    "name": "AltandΓΆrr"
}
dezral commented 6 years ago

a 5 sec pulling would be nice, it seems that telldus is not gonna support local http events/actions even via lua some time soon.

the pulling could be used on door sensors and other things like alarms.. but should be a setting one would use on specific switches or other.. like "pull": true setting in config.json

jonerikandersen commented 6 years ago

Any update on this? This could solve my doorbell issue. It detects it as a motion-sensor, but does not update state on either timeout or inactivity.

atchoo78 commented 4 years ago

If there is a way to listen for events in telldus api it would be even better.

@mifi : What about the Event manager in Telldus Live? It's possible to trigger a POST request on specified device event:

Skjermbilde 1

edit: ah....nevermind, going in circles here πŸ™„

mifi commented 4 years ago

Yea but then we would need to listen on a public HTTP server for these http requests. I think this was discussed before but I didnt find an easy solution

atchoo78 commented 4 years ago

I figured out a way to do this yesterday. Tried it during the day and it seem like a decent workaround at least.. Dunno if this is old news, so I'll try to give you the "quick start guide" first πŸ€·πŸ»β€β™‚οΈ

  1. Goes without saying, but I'll say it anyway: Install Homebridge and Homebridge-Telldus. Use the Live! API for starters.

I don't know if it's relevant yet (I've used Homebridge for 2 days), but I run Homebridge with -D and -I (accessory control seems like an essential option).

  1. Add one Door/Window magnet sensor in Telldus Live, if you haven't done so already.

  2. Add any necessary entries to "unknown accessories" in the config.json. The contact sensor is the most important, of course. Example:

...
            "unknown_accessories": [
                {
                    "id": 5815808,
                    "model": "contact-sensor",
                    "manufacturer": "Nexa"
                },
                {
                    "id": 6845735,
                    "model": "contact-sensor",
                    "manufacturer": "Telldus"
                }
            ]
...

4. Clear any leftover stale configuration cache from Homebridge and just check that it's up and running.

Now for the "interesting" part. Keep in mind that I'm fairly new to HB (but not to programming, debugging & coding in general though πŸ˜…).

I guess there are more convenient methods of doing this, but this was what I had at that point, so I just kept going.

  1. Use curl (or any web request service that is not a web browser) and send a GET request to the "accessories" endpoint at your homebridge IP/port. Just to avoid any confusion, do it from the same computer you're running Homebridge on:
 curl -X GET http://localhost:51826/accessories

If you have added some devices to Homebridge, you'll receive a looong JSON response with the complete accessory storage DB (minified, not like this guide. πŸ€“).

6. So, what I did, was to copy the whole "accessories" JSON, and pasted it into "TextMate".
⌘+A and "Reformat JSON" (pretty-print, human readable, whatever...same thing), just to get a clear view of the data in it. I guess any decent JSON editor is sufficient.

Long story short, I ended up with a structure that looked like the following:

(Come to think of it, it's actually the only part of the output we need for this)

🏠
"aid": 27,
"services": [
{
"iid": 1,
"type": "0000003E-0000-1000-8000-0026BB765291",
"characteristics": [
    {
        "iid": 2,
        "type": "00000014-0000-1000-8000-0026BB765291",
        "perms": [
            "pw"
        ],
        "format": "bool",
        "description": "Identify"
    },
    {
        "iid": 3,
        "type": "00000020-0000-1000-8000-0026BB765291",
        "perms": [
            "pr"
        ],
        "format": "string",
        "value": "Nexa",
        "description": "Manufacturer"
    },
    {
        "iid": 4,
        "type": "00000021-0000-1000-8000-0026BB765291",
        "perms": [
            "pr"
        ],
        "format": "string",
        "value": "contact-sensor",
        "description": "Model"
    },
    {
        "iid": 5,
        "type": "00000023-0000-1000-8000-0026BB765291",
        "perms": [
            "pr"
        ],
        "format": "string",
        "value": "Main Door",
        "description": "Name"
    },
    {
        "iid": 6,
        "type": "00000030-0000-1000-8000-0026BB765291",
        "perms": [
            "pr"
        ],
        "format": "string",
        "value": "xxx",
        "description": "Serial Number"
    },
    {
        "iid": 7,
        "type": "00000052-0000-1000-8000-0026BB765291",
        "perms": [
            "pr"
        ],
        "format": "string",
        "value": "1.0",
        "description": "Firmware Revision"
    }
],
"primary": false,
"hidden": false
},
{
"iid": 12,
"type": "00000080-0000-1000-8000-0026BB765291",
"characteristics": [
    {
        "iid": 13,
        "type": "00000023-0000-1000-8000-0026BB765291",
        "perms": [
            "pr"
        ],
        "format": "string",
        "value": "Main Door",
        "description": "Name"
    },
    {
🏠       "iid": 14,
        "type": "0000006A-0000-1000-8000-0026BB765291",
        "perms": [
            "pr",
            "ev"
        ],
        "format": "uint8",
🏠       "value": 0,
        "description": "Contact Sensor State",
        "valid-values": [
            0,
            1
        ],
        "maxValue": 1,
        "minValue": 0
    },

Be aware of the first and the last sections of the above JSON. These are however the values we need. (I marked them with 🏠):

"aid" (accessory ID) "iid" (Just yet another form of UUID)

and "value"

7. To trigger an update in the contact sensor (or its main characteristic value to be exact) , we can send a HTTP "PUT" request with the new values (I found this out randomly when I was about to give up 🀫)

This request HAS to be sent with authentication headers as well as a "Content-Type:Application/json" header. You'll find the "authorization pin" by the QR code in HomeBridge (default HomeKit connect code)

Full example:


curl -X PUT http://localhost:51826/characteristics --header "Content-Type:Application/json" --header "authorization: 123-45-678" --data "{ \"characteristics\": [{ \"aid\": 27, \"iid\": 14, \"value\": "0"}] }"

response:
{"characteristics":[{"aid":27,"iid":14,"status":0}]}  

A "0" value for "contact", of course means "No contact" == the door is open (and vice versa)

By the way, I just became aware of this one:


    "iid": 15,
        "type": "00000079-0000-1000-8000-0026BB765291",
    "perms": [
    "pr",
    "ev"
     ],
           "format": "uint8",
           "value": 0,
       "description": "Status Low Battery",
           "valid-values": [
    0,
    1
    ],
    "maxValue": 1,
    "minValue": 0
    }

Lo and behold. If I send


curl -X PUT http://localhost:51826/characteristics --header "Content-Type:Application/json" --header "authorization: 123-45-678" --data "{ \"characteristics\": [{ \"aid\": 27, \"iid\": 15, \"value\": "1"}] }"

...the battery status changes (= notification)!

So what I've done as a temporary thing, is to configure a simple python webserver that sends an update request to HomeKit/HomeBridge with the correct state value. In Telldus Live, I have an event configured to send a HTTP POST request to my python server with the state value as URL parameter, whenever the contact sensor senses anything.

Python then sends the "PUT" request instantly to Homebridge, and:

Skjermbilde IMG_2471

It works, kind of πŸ™‚ my 5 cents, at least

My loose plan is to make a HB Plugin which acts kind of like a middle man between Telldus Live and HomeBridge-Telldus for sensor events (contact sensors, door bells, push buttons, motion detectors..). The ideal thing would be to have it integrated into the Homebridge-Telldus plugin rather than creating another plugin...seems like hassle for users.

Is that doable? @mifi

The Telldus Live trigger event could also be a Lua script locally, that's even smoother.😳

atchoo78 commented 4 years ago

I just created a Tellstick plugin that (hopefully) will keep the contact sensors and their notifications in sync. I'm gonna try it out later and see if it's working the way I hope it does (!)

Basically it adds two helper functions to the local Telldus API, and it is intended to automatically push changes to HomeKit accessory characteristics on events regardless of origin app πŸ₯³πŸ™ˆ

Skjermbilde 1 Skjermbilde 3

atchoo78 commented 4 years ago

Hm. This actually worked great up until a recent Homebridge update. Now I get a "-70404" error whenever I do a "PUT" request to a contact sensor.

-70404 is the status code for "Cannot write to Read only property"

@mifi Any insights?

mifi commented 4 years ago

I think you just need to downgrade homebridge for now. I don't really have time or equipment to work on or test this now. But PR's are welcome!

atchoo78 commented 4 years ago

I figured it out. Instead of sending a "PUT" request on characteric change, send:

curl -X GET <homebridge ip>:51826/characteristics?id=<aid>.<iid>

Example where "aid" for the accessory is 17 and "iid" for property "contact sensor state" is 10:

curl -X GET http://localhost:51826/characteristics?id=17.10

This should in fact be the default callback for all Telldus devices (accessories). It would eliminate the need for any extra scripting.