Insteon Keypad + Phillips Hue

I want to control a Phillips Hue bulb with a button on an Insteon Keypad. However, I also need the keypad button to light up when the bulb is turned on from another source, so I need rules both ways. The problem is that these rules crash into each other (e.g. if I push the button, a rule turns the bulb on, but then that triggers the rule for the button, etc., etc.).

I’ve looked at the solutions to this kind of thing, but they all seem cumbersome. I’ve used a timestamp approach for now (see below), but it seems like there should just be an easier way using some combination of received update/received command/changed. Any thoughts?

Thanks,

Bruce

var FrontTableUpdate = now
var latency = 2

rule "Front Table Lamp Changed to ON"
    when Item EntryKeypadD changed from OFF to ON
then
	if(FrontTableUpdate.isBefore(now.minusSeconds(latency))) {
		logInfo("KeypadRules", "Entry Keypad D Changed from OFF to ON")
		FrontTableUpdate=now
		FrontTableLamp_Brightness.sendCommand(100)
	} else {
		logInfo("KeypadRules", "Entry Keypad D Changed, but update was recent")
	}
end

rule "Front Table Lamp Chagned to OFF"
    when Item EntryKeypadD changed from ON to OFF
then
	if(FrontTableUpdate.isBefore(now.minusSeconds(latency))) {
		logInfo("KeypadRules", "Entry Keypad D Changed from ON to OFF")
		FrontTableUpdate=now
		FrontTableLamp_Brightness.sendCommand(0)
	} else {
		logInfo("KeypadRules", "Entry Keypad D Changed, but update was recent")
	}
end


rule "Front Table Lamp Button (Change from 0)"
	when Item FrontTableLamp_Brightness changed from 0
then
	if(FrontTableUpdate.isBefore(now.minusSeconds(latency))) {
        	logInfo("KeypadRules", "Front Table Lamp just turned on - turning on button too")
		FrontTableUpdate=now
		EntryKeypadDset.sendCommand(ON)
	} else {
		logInfo("KeypadRules", "Front Table Lamp changed, but update was recent")
	}
end


rule "Front Table Lamp Button (Change to 0)"
	when Item FrontTableLamp_Brightness changed to 0
then
	if(FrontTableUpdate.isBefore(now.minusSeconds(latency))) {
        	logInfo("KeypadRules", "Front Table Lamp just turned off - turning off button too")
		FrontTableUpdate=now
		EntryKeypadDset.sendCommand(OFF)
	} else {
		logInfo("KeypadRules", "Front Table Lamp changed, but update was recent")
	}
end

This is not the same problem as the Manual Trigger detection solves, though clearly you can solve it with that DP.

The problem is that you need to synchronize the state of the keypad with the state of the bulb. You actually don’t care where the event came from in this case, just that the two Items are out of sync.

When one of the two Items changes state, all you need to do is check to see if the other one is already in the same state and send the command to it if it doesn’t. If they are already of the same state do nothing, which kills the loop.

rule "Keypad D changed"
when
    Item EntryKeypadD changed
then
    if(previousState == NULL) return; // don't do anything if the change was from NULL

    if(FrontTableLamp_Brightness.getStateAs(OnOffType) != EntryKeypadD.state) { // you can get the state of a Dimmer as if it were a Switch
        FrontTableLamp_Brightness.sendCommand(EntryKeypadD.state)  // you can send Switch commands to Dimmers
    }
end

rule "Front Table Lamp changed"
when
    Item FrontTableLamp_Brightness changed
then
    if(previousState == NULL) return;

    if(EntryKeypadD.state != FrontTableLamp_Brightness.state) {
        EntryKeypadD.sendCommand(FrontTableLamp_Brightness.getStateAs(OnOffType))
    }
end

Theory of operation:
If the keypad changes state and the new state doesn’t match the lamp’s state send the new state as a command to the lamp. If the keypad and lamp are already of the same state then do nothing.

If the lamp changes state and the new state doesn’t match the keypad’s state, send the new state as the command to the lamp. If the lamp and the keypad are already of the same state then do nothing.

2 Likes

This works, but there is still sometimes latency on this: in some instances, the light turns on right after I press the button, in others it doesn’t change for 10 seconds or so. Ditto in reverse. Is this down to polling intervals? Does the insteon binding not see the key press immediately?

@varneyb on my hue lights I don’t see 10seconds. Possibly 2 max but most times instant.

I have been considering getting a plm modem vs a hub. Some reading suggest they see events happen faster. As right now my delays are acceptable, but not preferred. I am saving my $$ for other projects. In the future I want to test the plm modem vs the hub.