Hat jemand GOVEE im Einsatz ?
Hab begonnen den LBS zu schreiben - recht rudimentär noch alles, hab aber wohl kaum Zeit (und Lust) das ordentlich zu machen.
Mir reicht die Funktionalität erstmal ( eigentlich reicht on/off)
Hier mal der LBS:
Hab begonnen den LBS zu schreiben - recht rudimentär noch alles, hab aber wohl kaum Zeit (und Lust) das ordentlich zu machen.
Mir reicht die Funktionalität erstmal ( eigentlich reicht on/off)
Hier mal der LBS:
PHP-Code:
###[DEF]###
[name = Govee V0.0.1]
[e#1 = Enable #init=1]
[e#2 IMPORTANT = IP ]
[e#3 TRIGGER = get states ]
[e#4 TRIGGER = PWR state ]
[e#5 TRIGGER = Brightness ]
[e#6 TRIGGER = RGB as hex #init = aabbcc]
[a#1 = nothing ]
###[/DEF]###
###[HELP]###
###[/HELP]###
###[LBS]###
<?
function LB_LBSID($id) {
if ($E=logic_getInputs($id)) {
if (!isEmpty($E[2]['value'])) {
logic_setInputsQueued($id,$E);
logic_callExec(LBSID,$id);
}
}
}
?>
###[/LBS]###
###[EXEC]###
<?
define ("LOG1689","LBS19001689");
define ("LOG_STEP",'0');
define ("LOG_ERROR",'1');
require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
set_time_limit(0);
sql_connect();
$E=logic_getInputsQueued($id);
$enabled = $E[1]['value']; // LBS enable from $E[1]
$deviceIP = $E[2]['value']; // IP address from $E[2]
$devicePort = 4003;
$color['TemInKelvin'] = 7200;
$command = "";
if ($enabled) {
// Create a socket
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($socket === false) {
writeToCustomLog('LOG', 'LOG_ERROR', "socket_create() failed: " . socket_strerror(socket_last_error()));
$comOK = 0; // Communication error
} else {
// Connect to the Govee device
if (socket_connect($socket, $deviceIP, $devicePort) == false) {
writeToCustomLog('LOG', 'LOG_ERROR', "socket_connect() failed: " . socket_strerror(socket_last_error()));
$comOK = 0; // Communication error
} else {
// Define the command to send to the Govee device
if ($E[4]['refresh'] == 1){
if ($E[4]['value'] == true) {
// If $E[4] is true, send a command to turn on the device
$command = '{"msg":{"cmd":"turn","data":{"value":1}}}';
} else {
// If $E[4] is false, send a command to turn off the device
$command = '{"msg":{"cmd":"turn","data":{"value":0}}}';
}
}
if ($E[5]['refresh'] == 1) {
$brightness = $E[5]['value'];
$command = '{"msg":{"cmd":"brightness","data":{"value":'.$brightness.'}}}';
}
if ($E[6]['refresh'] == 1) {
$hex = $E[6]['value'];
$color['r'] = hexdec(substr($hex,0,1).substr($hex,0,1));
$color['g'] = hexdec(substr($hex,2,1).substr($hex,2,1));
$color['b'] = hexdec(substr($hex,4,1).substr($hex,4,1));
$command = '{"msg":{"cmd":"colorwc","data":{"color":{"r":'.$color['r'].',"g":'.$color['g'].',"b":'.$color['b'].'}}}}';
}
// Send the command to the Govee device
writeToCustomLog('LOG', 'LOG_STEP', "writing command =" . $command."");
if (socket_write($socket, $command, strlen($command)) == false) {
writeToCustomLog('LOG', 'LOG_ERROR', "socket_write() failed: " . socket_strerror(socket_last_error()));
$comOK = 0; // Communication error
} else {
}
// Close the socket
socket_close($socket);
}
}
}
sql_disconnect();
?>
###[/EXEC]###
Kommentar