Switch GPIO with homekit

Hello :slight_smile:

OK Homekit is running now on my openHAB2 and is paired with my Apple device. Well, whats the easiest way to switch GPIO with the homekit?
Ive tried it with a rules:

homekit.items
Switch Heater "Heizung" <switch> ["Switchable"]

homekit.rules
rule "homekit"
when
Item Heater received command
then
if (receivedCommand==ON ) {
executeCommandLine(“gpio write 0 0”)
}
else if (receivedCommand==OFF ) {
executeCommandLine(“gpio write 0 1”)
}
end

Well, it doesnt work. Does anyone have a better idea or can see whats going wrong? Thank you :slight_smile:

Why don’t you use the GPIO binding for GPIOs? I guess that will make it easier.

Just don’t try to use Persistence with that binding, that will not work - that’s the error I made.

hmmm OK I could try it but how should the items file looks like to work with the gpio binding?

There’s documentation for the GPIO binding :wink:
https://docs.openhab.org/addons/bindings/gpio1/readme.html

Try that:

gpio.items

Switch LR_Heater_Switch "Heater" {gpio="pin:0 initialValue:low"}

homekit.rules

rule "homekit"
when
	Item Heater changed
then
	LR_Heater_Switch.sendCommand(Heater.state.toString)
end

Unfortunetely it doesnt work :frowning:

Can you be more specific on “doesnt work”?
What about watching the logs and reading them?

Ill try to catch the moment where I push the “on” button :smiley:

==> /opt/openhab2/userdata/logs/events.log <==
2018-02-10 20:54:59.398 [vent.ItemStateChangedEvent] - LR_Heater_Switch changed from OFF to ON
==> /opt/openhab2/userdata/logs/openhab.log <==
2018-02-10 20:54:59.396 [INFO ] [impl.connections.SubscriptionManager] - Publishing changes for 1104753297
2018-02-10 20:54:59.406 [TRACE] [lfe.hap.impl.http.impl.BinaryHandler] - Sending data [/192.168.10.21:56837]:
00000000 45 56 45 4E 54 2F 31 2E 30 20 32 30 30 20 4F 4B EVENT/1.0 200 OK
00000010 0D 0A 43 6F 6E 74 65 6E 74 2D 74 79 70 65 3A 20 …Content-type:
00000020 61 70 70 6C 69 63 61 74 69 6F 6E 2F 68 61 70 2B application/hap+
00000030 6A 73 6F 6E 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 json…Content-Le
00000040 6E 67 74 68 3A 20 36 31 0D 0A 43 6F 6E 6E 65 63 ngth: 61…Connec
00000050 74 69 6F 6E 3A 20 6B 65 65 70 2D 61 6C 69 76 65 tion: keep-alive
00000060 0D 0A 0D 0A 7B 22 63 68 61 72 61 63 74 65 72 69 …{“characteri
00000070 73 74 69 63 73 22 3A 5B 7B 22 61 69 64 22 3A 31 stics”:[{“aid”:1
00000080 31 30 34 37 35 33 32 39 37 2C 22 69 69 64 22 3A 104753297,“iid”:
00000090 39 2C 22 76 61 6C 75 65 22 3A 74 72 75 65 7D 5D 9,“value”:true}]
000000A0 7D }
2018-02-10 20:54:59.406 [INFO ] [impl.connections.SubscriptionManager] - Publishing changes for 1104753297
2018-02-10 20:54:59.409 [TRACE] [lfe.hap.impl.http.impl.BinaryHandler] - Sending data [/192.168.10.2:49910]:
00000000 45 56 45 4E 54 2F 31 2E 30 20 32 30 30 20 4F 4B EVENT/1.0 200 OK
00000010 0D 0A 43 6F 6E 74 65 6E 74 2D 74 79 70 65 3A 20 …Content-type:
00000020 61 70 70 6C 69 63 61 74 69 6F 6E 2F 68 61 70 2B application/hap+
00000030 6A 73 6F 6E 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 json…Content-Le
00000040 6E 67 74 68 3A 20 36 31 0D 0A 43 6F 6E 6E 65 63 ngth: 61…Connec
00000050 74 69 6F 6E 3A 20 6B 65 65 70 2D 61 6C 69 76 65 tion: keep-alive

and so one…there is much more in the logs but maybe u can see with this part whats going wrong

I can’t see something wrong - the opposite: I can see that the newly configured switch goes on:

2018-02-10 20:54:59.398 [vent.ItemStateChangedEvent] - LR_Heater_Switch changed from OFF to ON

That’s what we want.

By the way: I don’t think we need TRACE log level :wink:

So can you please be more specific on “doesnt work”?

OK which infos do you need exactly?
The switch on the home app of ios is switching…log looks like:

2018-02-10 21:17:48.120 [ome.event.ItemCommandEvent] - Item ‘LR_Heater_Switch’ received command ON
2018-02-10 21:17:48.145 [vent.ItemStateChangedEvent] - LR_Heater_Switch changed from OFF to ON
2018-02-10 21:17:49.601 [ome.event.ItemCommandEvent] - Item ‘LR_Heater_Switch’ received command OFF
2018-02-10 21:17:49.612 [vent.ItemStateChangedEvent] - LR_Heater_Switch changed from ON to OFF

The GPIO Pin is also used by another item (switch) to switch it on and off with a touch panel (this is working)
ok…and thats was the problem. I just added an “switchable” behind the switch for the panel, got it in the home app and it worked…
Thank you very much for your help :slight_smile:

Great :slight_smile: You are welcome!

In general: A detailed description on what you want to do (what input, what output) and what happens instead (hardware status changes, configs, logs, …) help to understand the problem and give you advice. “It doesn’t work” provides none of that and makes it really difficult to help.