From: Richard Z. <rs...@gm...> - 2012-09-13 16:39:20
|
I'm tying a button on a KeypadLinc to a OutletLinc. I've got everything done according to the documentation, and it all seems to work. Here's my MHT: IPLD, 15.8F.8D:01, driveway_light_device, hidden, PLM, # outletlinc IPLL, 08.4A.B7:01, porch_light, All_lights, PLM, # keypadlinc IPLL, 08.4A.B7:03, kpl1_button_a, buttons, PLM, # keypadlinc # Setup Driveway Light and KPL buttons SCENE_MEMBER, driveway_light_device, kpl1_button_a IPLL, PLM:81, driveway_light, All_lights, PLM, SCENE_MEMBER, kpl1_button_a, driveway_light SCENE_MEMBER, driveway_light_device, driveway_light So now I've got a scene called driveway_light that when I turn it on I update both the light and the KPL button. To tell MH that the scene driveway_light is on when I hit the button locally, I've added this perl code: if ($Reload or $Startup) { $driveway_light_device->tie_event('sync_kpl_lights($driveway_light_device, $driveway_light)'); } # Every time a switch is toggled locally, or every time you run # get_status or on receipt of remote activations, also update the # scene containing the light to keep them in sync. sub sync_kpl_lights { my ($ref_light, $kpl_scene) = @_; # avoid unnecessary traffic, like a get_status where status hasn't changed. if ($ref_light->state_changed) { print_log "MYLOGKPL: sync_kpl_lights called for state_changed on ". $ref_light->get_object_name." to ".$ref_light->state." for ". $kpl_scene->get_object_name." set kpls in 1sec"; # delay is to avoid collisions. In case we're in this code path # due to a remote toggle instead (you pushed the switch), that switch # could already be running a scene and you don't want to conflict with it # (for local state changes, this is not an issue). $kpl_scene->set_with_timer('', 1, $ref_light->state); } } so, here's my question. The code above seems a bit hacky. For one, when I hit the KPL button, it turns on the KPL light, and the driveway_light_device. MH then sees the device turn on, fires the event above, which turns on the scene (after 1 second). That in turn tells the KPL button and the driveway_light_device to turn on --*again--.* That seems like an unnecessary step. The 1 second delay also seems problematic if my KPL button has the light turn on at a rate slower than 1s, the second "on" notice will step on the slow ramp before it's done. So, isn't there a way to set the "state" of the driveway_light scene to be 'on' without actually firing the scene and all its associated members? (something like $driveway_light->state = ON; ) |