$log->lwrite("Switch update necessary"); $msg = "!R" . $dev_config[$i]['room'] . "D" . $d . "F" . $v; $log->lwrite("Message to send: " . $msg); send_2_daemon($msg); } } else { $d = substr($id, 1); $ret = zway_dim_stat($ch, $d); // Get the Zwave value and normalize to LamPI values 1-32 $v = ceil(zway_dim_get($ch, $d) / 99 * 32); if ($v != $val) { $log->lwrite("zway_dim_get:: returned: " . $v, 2); $log->lwrite("Dimmer update necessary with value: " . $v); $msg = "!R" . $dev_config[$i]['room'] . "D" . $d . "FdP" . $v; $log->lwrite("Message to send: " . $msg); send_2_daemon($msg); } //echo "Appmsg: ".$appmsg."\n"; //echo "Apperr: ".$apperr."\n\n"; } $log->lwrite("Done zwave device name: " . $name . ", id: " . $id . ", gaddr: " . $gaddr . ", LamPI val: " . $val . ", zway val: " . $v); } else { if ($debug >= 2) { echo "Not Found zwave device id: " . $id . "\n"; } } } //$v = zway_dim_get ($ch,3); //$log->lwrite("Start looking for and update function, zway_dim_get : ".$v); //$v = ceil($zparse["devices."."3".".instances.0.commandClasses"]["38"]["data"]["level"]["value"]); //$v = ceil($zparse["devices"]["3"]["instances"]["0"]["commandClasses"]["38"]["data"]["level"]["value"]);
} } //else $log->lwrite("\tSwitch ".$unit.":: Value ".$zway_val." read",0); $log->lwrite("\tSwitch " . $unit . ":: Raw: " . $zway_val . " Value <" . $zway_val . ">", 0); // As soon as gui-val and zway-val are equal, no work to be done // if ($gui_val == $zway_val) { // The values are valid, make value 0 to mark we're set $zway_dev[$i]['gui_inValid'] = 3; } else { if ($zway_dev[$i]['gui_inValid'] <= 0) { // A Change made with the device switch $log->lwrite("\tSwitch update with value: " . $zway_val, 0); $msg = "!R" . $dev_config[$i]['room'] . "D" . $unit . "F" . $zway_val; $log->lwrite("\tMessage to send: " . $msg, 2); send_2_daemon($msg, $daemonIP); // XXX Does it update lastval as well? } else { if ($gui_val != $zway_dev[$i]['gui_old']) { $log->lwrite("Switch val inValid:: " . $zway_dev[$i]['name'] . ": gui_old: " . $zway_dev[$i]['gui_old'] . ", gui_val: " . $gui_val . ", zway_val: " . $zway_val, 0); $zway_dev[$i]['gui_inValid']--; } else { // Unknown State, decrease counter. When this happens we wait another cycle $log->lwrite("Switch state change:: " . $zway_dev[$i]['name'] . " gui_old: " . $zway_dev[$i]['gui_old'] . ", gui_val: " . $gui_val . ", zway_val: " . $zway_val, 0); $log->lwrite("\tupdateTime:: " . @date('[d/M/y, H:i:s]', $updateTime) . ", " . $updateInterval . " seconds ago", 1); $log->lwrite("\tinvalidateTime is " . (time() - $updateTime) . " seconds ago", 2); $zway_dev[$i]['gui_inValid']--; // // If the interval is unrealistic, the reported zway value might be in error (internal zway error) // In this case we should not decrease the value but set back the zway value to // the correct value in the LamPI system
case "action": $appmsg .= "\naction: " . $action . ", dmon_msg: " . $dmon_msg; $ret = send_2_daemon($dmon_msg); break; // Scenes will be forwarded to the daemon // Scenes will be forwarded to the daemon case "scene": $appmsg .= "scene:: send_2_daemon: " . $dmon_msg . "\n"; $ret = send_2_daemon($dmon_msg); // See above break; // Generic command to the daemon ... if necessary use json to format the command nicely // Generic command to the daemon ... if necessary use json to format the command nicely case "send_2_daemon": $appmsg .= "send_2_daemon:: send_2_daemon: " . $dmon_msg . "\n"; $ret = send_2_daemon($dmon_msg); break; default: $appmsg .= "action: " . $action; $apperr .= ", Rasp:" . $action . ", command not recognized\n"; $ret = -1; } if ($ret >= 0) { $send = array('tcnt' => $ret, 'status' => 'OK', 'appmsg' => $appmsg, 'apperr' => $apperr); $output = json_encode($send); } else { //$apperr .= $appmsg; $apperr .= "\nrasp returns error \n" . $ret; $send = array('tcnt' => $ret, 'status' => 'ERR', 'appmsg' => $appmsg, 'apperr' => $apperr); $output = json_encode($send); }