New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to correctly update value of characteristic #543
Comments
getCharacteristic(...).setValue(VALUE,...) is used by an iOS controller to change a characteristic. If you want to update a characteristic from the "accessory" side, use updateValue instead of setValue. That will also update the state in iOS, if the characteristic supports events and was subscribed to by an iOS controller. |
@grober so from a plugin for homebridge to attach my own accessory I need to use updateValue, right? |
yes |
Is there any case, where I should use setValue for a homebridge plugin? |
AFAIK no. |
Using setValue will trigger the ‘set’ event in your plugin, so use it where it makes sense. If you don’t have a ‘set’ event in your plugin it works the same as updateValue.
PS I’m working on a pull request to add the ability to at an error condition for a plugin.
https://github.com/KhaosT/HAP-NodeJS/pull/539
… On Jan 6, 2018, at 12:04 PM, Michael Fröhlich ***@***.***> wrote:
AFAIK no.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Changed everything to updateValue, but still notification do not appear reliable. If I open the HomeApp allmissing notifications appear. Maybe someone can look at my plugin to see whats wrong. Its happening both of my plugins https://github.com/benzman81/homebridge-http-webhooks and https://github.com/benzman81/homebridge-nukiio Thanks in advance. |
First, there is or was an issue with remote notification of motion sensor events. I had patched my HAP-NodeJS a long time ago, and haven't looked to see if it has been fixed by Apple lately. https://github.com/KhaosT/HAP-NodeJS/issues/418 Are you experiencing this? Second, I took a quick look at you code and and it seemed reasonable but also may have some issues around events. Is your changeHandler being fired when an incoming event occurs? Third, to debug this I presume you have turned on HAP-NodeJS debugging, and are looking at HAP interactions with Home. For notifications to work the Accessory needs to register for events ( this is visible in debug ), and notifications need to be turned on in the Home app. When update events are sent, HAP is pretty chatty when in Debug. Forth, with updateValue HAP-NodeJS doesn't propagate events with the same value, so no need to only send updates for change. Lastly, in my sensor plugins I have totally stopped implementing the .on('get' event listener, and totally rely on updateValue for updates. |
Wow, this is getting complicated :-) first) I experience the issues mostly with contact/occupany sensors and locks, so if there was a bug with motion sensors, this shouldn't be the problem. But maybe its the same with other events, too. second) the change handler is only called if the internal http server receives a matching request from some other home systems or a browser. third) i never have turned on the debug for homebridge, will try that if I find some more time. fourth) Since the updateValue is called from outside (the http server), I guess it is the correct way to call the update of hap and iOS,is it? fifth) do you a plugin I can look at? is this only working with your repo or also with the official HAP-NodeJS? |
@benzman81 Once you have it working, it works really well but getting everything lined up the first time does take some effort. I had spent a few months looking at various things thru trial and error before it go it all working what I would call trouble free and reliably. #3 Make sure it is HAP-NodeJS debugging..ie DEBUG=* homebridge #4 - as long as you can access the accessory, it should be fine. With debugging you should be able to ensure that the messages are getting thru. #5 - I have been using this as a test bed for new ideas https://github.com/NorthernMan54/homebridge-mcuiot/blob/master/index.js Please note, in this I implemented device polling, rather than putting up a listener for the devices to update. I have started on a new version based on having a listener, and having the devices connect but it isn't complete yet. ( I do have the motion sensor working though, also if updateValue looks wacky it is because I was playing with an early concept of my pull request #539 ). https://github.com/NorthernMan54/homebridge-wssensor For HAP-NodeJS, using the stock version is fine, you just need to be aware of #418 . I have my own version, as I had enhanced it to also support using alexa to control my accessories. |
Fixed in tvOS 11, ebaauw/homebridge-hue#118 (comment).
Except, of course, for the ProgrammableSwitchEvent characteristic ;-)
Same here. |
In the log below I tests a contact sensor an a lock. Whenever an entry with [HttpWebHooks] or [INFO Nuki WebHook Server] is liste a call from an external system was done to update the state in home bridge/homekit. Mostly I receive no notification, but sometime I do. Currently it seems that the lock notification never comes through, but the contact sensor does sometime. Any ideas? `
|
@benzman81 That looks okay from the point of view of events. Your devices are at HAP id 30.9 and 47.10 I see these lines, which is showing the events going to your devices @ 10.0.1.132 and 10.0.1.109, and this looks normal. The line I was look at was Sending "HTTP event" My only comment is that it seems to flip state back and forth very quickly, less than a second @ 16:42:03 and over 5 seconds @ 16:42:43 Have you checked in the home app that notifications are enabled for the accessory? 08 16:42:48 | stderr | Mon, 08 Jan 2018 16:42:48 GMT EventedHTTPServer [::ffff:10.0.1.132] Sending HTTP event '30.9' with data: {"characteristics":[{"aid":30,"iid":9,"value":0}]} 2018-01-08 16:42:48 | stderr | Mon, 08 Jan 2018 16:42:48 GMT EventedHTTPServer [::ffff:10.0.1.109] Sending HTTP event '30.9' with data: {"characteristics":[{"aid":30,"iid":9,"value":0}]} 2018-01-08 16:42:48 | stdout | [2018-1-8 16:42:48] [HttpWebHooks] Change HomeKit state for contact sensor to 'true'. 2018-01-08 16:42:43 | stderr | Mon, 08 Jan 2018 16:42:43 GMT EventedHTTPServer [::ffff:10.0.1.132] Sending HTTP event '30.9' with data: {"characteristics":[{"aid":30,"iid":9,"value":1}]} 2018-01-08 16:42:43 | stderr | Mon, 08 Jan 2018 16:42:43 GMT EventedHTTPServer [::ffff:10.0.1.109] Sending HTTP event '30.9' with data: {"characteristics":[{"aid":30,"iid":9,"value":1}]} 2018-01-08 16:42:43 | stdout | [2018-1-8 16:42:43] [HttpWebHooks] Change HomeKit state for contact sensor to 'false'. 2018-01-08 16:42:29 | stdout | [2018-1- PS When sharing a large log, using a file sharing service like google drive may be preferred as it makes it easier to pull into an editor for review. |
I just don't get it. I tested a lot using my plugin homebridge-http-webhooks. As test I added a contact sensor. Then I keep calling the url to update the state with http://ip:51828/?accessoryId=window1&state=true and http://ip:51828/?accessoryId=window1&state=false. I would expect, that switching between true and false always gives me a notification, but it just doesn't. If I have the Home app open and keep calling these URLs, I always see the state of the contact sensor switching as expected. It just seems to be an issue with notifications. Maybe it's not a bug of homebridge/hap-nodejs but a bug of homekit. I would be glad if someone could try it out using my plugin and investigating the problem. I have no clue now how to fix this. |
I get notifications alright from Contact Sensors exposed by homebridge-hue. Sorry for asking the obvious, but you did switch on Notifications in Apple's Home app on each iPhone/iPad you want to receive them? |
Hi, no problem for asking. I turned on notifications for the sensor on my iphone and my ipad, and both dont get notifications pretty often, and pretty often they do, I would say success rate is about 50% ;-) |
I use the updateValue function of a characteristic and don’t have challenges. But if your having issues, DEBUG=*, will show you what is happening with events between your device and HomeKit.
I’m using motion sensors, and they are working very well.
… On Jan 18, 2018, at 2:30 PM, Markus Krüger ***@***.***> wrote:
Hi, no problem for asking. I turned on notifications for the sensor on my iphone and my ipad, and both dont get notifications pretty often, and pretty often they do, I would say success rate is about 50% ;-)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
HomeKit notification blues... Maybe this helps: ebaauw/homebridge-hue#118 (comment) |
Ok, its pretty weird. I can see the following behavior.
I can see a similar behavior using notifications for locks. Motion, smoke, and occupancy work as expected. Using debug, I can see that homebridge/HapNode.js is always sending the events, but notifications stop after third request. What is also interesting, that I can repeat the same scenario after waiting a few minutes. Sometimes even starts working again after some more seconds. |
Ok, I just added automations based on a contact sensor and a lock. And they are always working. |
Hi: curl -sX PUT $url --header "$content" --header "$auth" --data "{\"characteristics\":[{\"aid\":1,\"iid\":10,\"value\":$accion}]}" And it always fires the "set" event, and turn on/off the light. I want to only update the state of the characteristic, and not change the state. Thanks! |
@p3ntium
The HAP api you are using doesn’t support that use case. It only supports GET and SET and it doesn’t support update. For full details on the API, read the apple spec document.
… On Mar 2, 2018, at 7:10 PM, p3ntium ***@***.***> wrote:
Hi:
how can I use the updateValue function from external script?
Now I'm sending the external changes to HAPNode through an HTTP request like this:
curl -sX PUT $url --header "$content" --header "$auth" --data "{\"characteristics\":[{\"aid\":1,\"iid\":10,\"value\":$accion}]}"
And it always fires the "set" event, and turn on/off the light. I want to only update the state of the characteristic, and not change the state.
Thanks!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <https://github.com/KhaosT/HAP-NodeJS/issues/543#issuecomment-370094071>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AS5CmFWvm1asYdA22hjCyQhoJeW021XZks5tad-NgaJpZM4RVS8H>.
|
Any idea or recommendation? I have my house with X10 elements and I send the update states to HAP-NodeJS through the url mentioned above, then it always execute again the command sent in the update... Thanks in advance |
How are you interfacing with X10? For my setup I use heyu and the homebridge-heyu plugin, which supports updates.
…Sent from my iPad
On Mar 5, 2018, at 4:35 AM, p3ntium ***@***.***> wrote:
Any idea or recommendation? I have my house with X10 elements and I send the update states to HAP-NodeJS through the url mentioned above, then it always execute again the command sent in the update...
Thanks in advance
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Great! My X10 interface is Heyu too. Regards! |
Under the covers homebridge is hap-nodejs, but just run an instance of homebridge for x10, and keep your other hap-nodejs instances going. When running everything, you just need to watch for port conflicts.
…Sent from my iPad
On Mar 5, 2018, at 6:45 AM, p3ntium ***@***.***> wrote:
Great! My X10 interface is Heyu too.
I have a problem for use Homebridge, because the X10 elements at my home only represents the 20% of the total, I have another elements DIY and other from unknown protocols, and all of them integrated with HAP-NodeJS. If I change to Homebridge I will have the update feature, but I will need to rewrite all the code to integrate with the other 80% of the elements.
Or... It's a good idea to combine the HAP-NodeJS with Homebridge? Will be two HAP servers on my house?
Regards!
Fran
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Update: curl -sX PUT http://$host:$port/update --header "$content" --header "$auth" --data "{"characteristics":[{"aid":1,"iid":10,"value":$accion}]}" If someone wants to check I can send the modified files. Regards!! |
Hello Everyone,
Can you show me a way to do this. |
Hi: curl -sX PUT http://localhost:$port/characteristics --header "Content-Type:Application/json" --header "Authorization: $pincode" --data "{"characteristics":[{"aid":1,"iid":$iid,"value":$value}]}" Do you understand? Regards |
I'm very sorry but can you make it more clarify for me. |
Hi,
there are multiple ways I found to update a value of a characteristic.
I found the following:
Currently I use getCharacteristic(...).setValue(VALUE,...) but i not always update the states in iOS from Background, only if I open the home app.
@KhaosT maybe you could explain what is the correct method and explain the differences. Thanks.
The text was updated successfully, but these errors were encountered: