Homebridge-hue: OSRAM outlet

Created on 17 Dec 2018  ·  41Comments  ·  Source: ebaauw/homebridge-hue

Is it possible for a OSRAM smart plug to be directy used as ‘valve’ instead of ‘outlet’ via ph -H [ip] valve -v ?

enhancement

All 41 comments

ph outlet just creates a resourcelink; the real logic is in homebridge-hue, exposing the resources from that resourcelink as _Outlet_ instead of _Lightbulb_.

What do you have connected to the OSRAM plug? I've never had a need for the _Valve_ service myself. It has mandatory characteristics _Active_, _In Use_, and _Valve Type_. I suppose you'd need a way to set _Valve Type_ as well (to _Generic Valve_, _Irrigation_, _Shower Head_, or _Water Faucet_). _Active_ is used instead of _On_. _In Use_ is mandatory for _Outlet_ as well, but I've never been able to figure out what its use is. My Eve Engery (native HomeKit) plugs report _In Use_ when a power cord is connected to it, regardless whether the smart plug or the appliance is on or off.

I have magnetic valves plugged in, so when the plug turns on, the valve opens and waters the garden. Therefor it would be neat to have the plug exposed as a valve to HomeKit.

Hello,

i'm new using Homebridge, and with your plugin, i'd like to know what to be changed to switch my Osram Plugs into Outlet instead of Lightbulb ?

Thanks

I haven't included this in the Wiki yet, but It's described in the release notes for v0.10.0: https://github.com/ebaauw/homebridge-hue/releases/tag/v0.10.0.

Thanks for this link, but I'm not able to do "ph outlet -v".

it repIies : "-bash: ph : commande introuvable" (its in french sorry)

Depending on how you installed NodeJS, it should install to /usr/bin or /usr/local/bin when installing homebridge-hue through sudo npm -g i homebridge-hue. This is the same directory where the homebridge executable is installed. Make sure this directory is in your PATH.

I've followed this link to install Homebridge from step 1.

image

so homebridge is then installed there : usr/home/pi/homebridge/

I've had this : "export PATH=$PATH:/usr/home/pi/homebridge"

But "ph outlet -v" still doesn't work

When installing using sudo npm -g i homebridge-hue, npm creates symlinks in /usr/bin or /usr/local/bin to cli/ph.js of homebridge-hue-utils. I don't know what the Docker installation looks like. Maybe you can create a symlink manually. Also make sure to chmod 755 cli/ph.js.

$ ll /usr/bin/ph
lrwxrwxrwx 1 root root 78 Dec 28 20:30 /usr/bin/ph -> ../lib/node_modules/homebridge-hue/node_modules/homebridge-hue-utils/cli/ph.js

Hello,

I am not able to define the OSRAM outlet as an outlet. It stays as a lamp.
I tried this command (ph -H 192.168.0.94 outlet -v) but I get the following message:
ph outlet: error: 1 unauthorized user
Is there a way to manually do it by creating the resourcelink file? If yes, where do I have to put it?

Thanks in advance

The resourcelink is not a file, but a resource on the deCONZ, created and updated through the REST API. To interact with the REST API, you need a valid username (API key). To create one for ph, unlock deCONZ for new applications and then run ph -H 192.168.0.94 createuser.

Hello,
Thanks for your quick answer. Unfortunately, I do not have a deCONZ. Only the hue bridge.
Does it means that I do not have anyway to set the device as an outlet?

Sorry, then press the big link button on the Hue bridge before running ph -H 192.168.0.94 createuser.

Have you looked in to perhaps changing the ‘outlet’ exposure to HomeKit to different types, like ‘valve’, as I suggested?

Looked: yes, implemented: not yet. Will give it a try this weekend.

Hello again,
Thanks very much.I succeed to do it.
Even if for me it is strange due to the fact I do not understand how you find what must be an outlet and what must stay as a lamp when setting outlet -v
Anyway, thanks again

That would be great, thanks so far. Would you mind giving me a heads up if there is any news on this to report?

Even if for me it is strange due to the fact I do not understand how you find what must be an outlet and what must stay as a lamp when setting outlet -v

The issue is that you don't. ph outlet creates an outlet resourcelink, containing the /lights resources with a type that doesn't end in "light". For the OSRAM plug this works, but for plugs or wired switches that report the wrong type, for groups, for other types of devices it doesn't. The resourcelink allows you to correct that manually. And it allows you to indicate that a plug connected to a light should be exposed as a light.

Thanks for the explanation, and thanks again for your support

Would you mind giving me a heads up if there is any news on this to report?

@rgerr, In v0.11.7. You'll need to create a resourcelink to list the /lights resources to be exposed as value by:
```
ph post /resourcelinks '{
"name": "homebridge-hue",
"description": "valve",
"classid": 1,
"links": [
"/lights/12",
"/lights/34"
]
}'

That would make all outlets be exposed as valves, if I’m correct?

No, just the ones listed in the resourcelink, in this example /lights/12 and /lights/34.

That sounds great. How to implement this? In the config and in terminal?

It's a command you enter at the command line (just like ph outlet).

So I use ph -H ip outlet -v or ph -H ip valve -v?

There’s no ph valve as there’s no way to know which resources to expose as valve. So use

ph -H _ip_ post /resourcelinks ’{ _body_ }’

With the body mentioned above, listing the /lights resources to expose as valves under the ”links”.

I’m haring trouble implementing this. What do I put in the terminal and what do I put in the config file?

In config: nothing; in the terminal (replacing the xs with the correct values):

ph -H x.x.x.x post /resourcelinks '{
  "name": "homebridge-hue",
  "description": "valve",
  "classid": 1,
  "links": [
    "/lights/xx",
    "/lights/xx"
  ]
}'

Great, got the valves in the Home app! Many thanks for that. Will it also be possible to set different valves, instead of the default valve? For instance, sprinkler?

Something I havent taken into account, the valve cannot be used in timed automations. So could you perhaps change/add the sprinkler function?

The valve type is hard-coded, but feel free to try and change it yourself.
https://github.com/ebaauw/homebridge-hue/blob/95654927241c24a10fbe141afcd810d79dde9bb5/lib/HueLight.js#L433-L434

As far as I can tell, nothing changes with a different valve type, except the symbol displayed in the Home app.

No, with a sprinkler you can set a timer. So you can turn it on for a (default) time. And use it in automation. I’m not sure what to look for in the code you linked, but is it possible to create the valve-sprinkler?

is it possible to create the valve-sprinkler?

Yes, change the line I mentioned above to ValveType.IRRIGATION. As I mentioned before, the only thing that changes is the symbol.

No, with a sprinkler you can set a timer. So you can turn it on for a (default) time. And use it in automation.

Can you please provide screenshots of what you mean?

Where exactly is the mentioned file? I’ll then change it there. Don’t have a screenshot of a sprinkler in HomeKit, but you can check it yourself, with e.g. homebridge-gpio-valve and use it as a dummy. (https://www.npmjs.com/package/homebridge-gpio-valve)

Where exactly is the mentioned file?

Depends on how you installed NodeJS and homebridge-hue. It's in the lib directory under the main homebridge-hue directory. When installed using npm -g, it's typically /usr/lib/node_modules/homebridge-hue/lib/HueLight.js or /usr/local/lib/node_modules/homebridge-hue/lib/HueLight.js

e.g. homebridge-gpio-valve

Looking at that code, the only "automation" they provide is an auto-close after a certain amount of time, specified by the optional _SetDuration_ characteristic. No schedules, no automatic opening the valve. They also provide the optional _Remaining Duration_ characteristic, but this is not persisted. The auto-close will not happen if homebridge is restarted while the valve is open.

This has nothing to do with the valve type - it's additional optional functionality for all valve types. I could probably add it to homebridge-hue. However, with the current design of homebridge-hue, _SetDuration_ and _Remaining Duration_ would be reset to the default across on each homebridge restart. And, as with the gpio-valve plugin, the auto-close will not happen if homebridge is restarted while the valve is open.

I do think this functionality would better (more robustly), albeit less user friendly, be implemented on the Hue bridge instead. A rule on the Hue bridge can turn state.on to false, a specified amount of time after it was turned on.

Could you try v0.11.10-0? It adds the _Set Duration_ and _Remaining Duration_ characteristics to the _Valve_ service. Install using sudo npm -g i homebridge-hue@beta.

Updated with the beta, now it works!

http://i64.tinypic.com/2jdju9y.png

Also changed ‘ValveType.GENERIC_VALVE’ to ‘ValveType.IRRIGATION’, now I have sprinklers in my Home app. Great!

Strange, with the homebridge-gpio-valve plug-in (as a dummy) I could use it in automations. Now I cannot.

Atleast not in the Apple Home app. In the Smart Home app of Matthias Hogatterer, I can.

What can you do in automations? Screenshot?

Look like Apple's Home doesn't see the valve as accessory to be controlled nor as sensor that detects something. In Eve, I can select _Watering_ (actually _Active_) and _In Use_ as triggers and _Watering_, _Default Duration_, _In Use_, and _Remaining_ as conditions.

Exactly, so in Apple’s native app, it is not supported to control the valve type in automation. Luckily, in some third party apps, it is. :)

v0.11.10 is out; I retired the beta.

For future reference for other users: with the 0.11.10 update you can also change default valve to e.g. irrigation, by changing line 434 from ‘ .updateValue(Characteristic.ValveType.GENERIC_VALVE)’ to ‘ .updateValue(Characteristic.ValveType.IRRIGATION)’ in the /usr/lib/node_modules/homebridge-hue/lib/HueLight.js file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jojost1 picture jojost1  ·  5Comments

derthobo picture derthobo  ·  3Comments

rgerr picture rgerr  ·  6Comments

jostrasser picture jostrasser  ·  3Comments

deanlyoung picture deanlyoung  ·  3Comments