Skip to content

Commit

Permalink
v.0.8-beta
Browse files Browse the repository at this point in the history
* Добавлена регулировка цветовой температуры (в кельвинах от 1700к до 6500к) для Yeelight.
* Добавлена регулировка цвета RGB (в формате hex) для Yeelight.
* Добавлена базовая поддержка Yeelight LED Lightstrip:
- получение текущего статуса;
- включение/выключение;
- регулировка яркости;
- регулировка цветовой температуры;
- регулировка цвета RGB.
* Добавлена базовая поддержка Yeelight Ceiling Light, Mi LED Desk Lamp, Philips EyeCare Smart Ceiling Lamp:
- получение текущего статуса;
- включение/выключение;
- регулировка яркости;
- регулировка цветовой температуры.
* Добавлена поддержка Mi Smart Power Strip 6 Plugs:
- получение текущего статуса (в т.ч. температура, потребляемая мощность и сила тока);
- включение/выключение;
- включение/выключение светодиода wifi.
* В интерфейс модуля добавлена кнопка для тестирования API-команд.
* В перечень устройств внесен Mi IR Remote 360.
* В About добавлена ссылка на тему на форуме.
  • Loading branch information
skysilver-lab committed Dec 15, 2017
1 parent 3e8e373 commit e80ceda
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 16 deletions.
11 changes: 7 additions & 4 deletions modules/xiaomimiio/miio_devices_edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @author <[email protected]>
* @copyright 2017 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 0.7b
* @version 0.8b
*/

if ($this->owner->name == 'panel') {
Expand Down Expand Up @@ -147,9 +147,12 @@
if ($properties[$i]['TITLE'] == 'cct') {
$properties[$i]['SDEVICE_TYPE'] = 'dimmer';
}
//if ($properties[$i]['TITLE'] == 'rgb') {
//$properties[$i]['SDEVICE_TYPE'] = 'rgb';
//}
if ($properties[$i]['TITLE'] == 'ct') {
$properties[$i]['SDEVICE_TYPE'] = 'dimmer';
}
if ($properties[$i]['TITLE'] == 'rgb') {
$properties[$i]['SDEVICE_TYPE'] = 'rgb';
}
if ($properties[$i]['TITLE'] == 'temperature') {
$properties[$i]['SDEVICE_TYPE'] = 'sensor_temp';
}
Expand Down
2 changes: 1 addition & 1 deletion modules/xiaomimiio/miio_devices_search.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @author <[email protected]>
* @copyright 2017 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 0.7b
* @version 0.8b
*/

global $session;
Expand Down
157 changes: 152 additions & 5 deletions modules/xiaomimiio/xiaomimiio.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
* @package project
* @author <[email protected]>
* @copyright 2017 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 0.7b
* @version 0.8b
*/

define ('MIIO_YEELIGHT_WHITE_BULB_PROPS', 'power,bright');
define ('MIIO_YEELIGHT_COLOR_BULB_PROPS', 'power,bright,ct,rgb,hue,sat,color_mode');
define ('MIIO_YEELIGHT_STRIP_PROPS', 'power,bright,ct,rgb,color_mode');
define ('MIIO_YEELIGHT_CEILING_LIGHT_PROPS', 'power,bright,ct');
define ('MIIO_YEELIGHT_LAMP_LIGHT_PROPS', 'power,bright,ct');

define ('MIIO_PHILIPS_LIGHT_BULB_PROPS', 'power,bright,cct,snm,dv');
define ('MIIO_PHILIPS_LIGHT_CEILING_PROPS', 'power,bright,cct');
define ('MIIO_PHILIPS_EYECARE_LAMP_2_PROPS', 'power,bright,notifystatus,ambstatus,ambvalue,eyecare,scene_num,bls,dvalue');

define ('MIIO_CHUANGMI_PLUG_M1_PROPS', 'power,temperature');
define ('MIIO_ZIMI_POWERSTRIP_2_PROPS', 'power,temperature,current,power_consume_rate,wifi_led,mode');

define ('MIIO_MIVACUUM_1_STATE_CODES', serialize (array('0' => 'Unknown',
'1' => 'Initiating',
Expand Down Expand Up @@ -406,7 +411,7 @@ function requestInfo($device_id) {
/**
* requestStatus
*
* ...
* Запрос статусов устройств
*
* @access public
*/
Expand Down Expand Up @@ -468,6 +473,46 @@ function requestStatus($device_id) {
$this->addToQueue($device_id, 'get_zigbee_channel', '[]');
}
$this->addToQueue($device_id, 'get_channels', '{"start":0}');
} elseif ($device_rec['DEVICE_TYPE'] == 'philips.light.ceiling') {
//
$props = explode(',', MIIO_PHILIPS_LIGHT_CEILING_PROPS);
$total = count($props);
for ($i = 0; $i < $total; $i++) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '['.implode(',',$props).']');
} elseif ($device_rec['DEVICE_TYPE'] == 'yeelink.light.ceiling1') {
//
$props = explode(',', MIIO_YEELIGHT_CEILING_LIGHT_PROPS);
$total = count($props);
for ($i = 0; $i < $total; $i++) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '[' . implode(',', $props) . ']');
} elseif ($device_rec['DEVICE_TYPE'] == 'yeelink.light.lamp1') {
//
$props = explode(',', MIIO_YEELIGHT_LAMP_LIGHT_PROPS);
$total = count($props);
for ($i = 0; $i < $total; $i++) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '[' . implode(',', $props) . ']');
} elseif ($device_rec['DEVICE_TYPE'] == 'yeelink.light.strip1') {
//
$props = explode(',', MIIO_YEELIGHT_STRIP_PROPS);
$total = count($props);
for ($i = 0; $i < $total; $i++) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '[' . implode(',', $props) . ']');
} elseif ($device_rec['DEVICE_TYPE'] == 'zimi.powerstrip.v2') {
//
$props = explode(',', MIIO_ZIMI_POWERSTRIP_2_PROPS);
$total = count($props);
for ($i = 0; $i < $total; $i++) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '[' . implode(',', $props) . ']');
}

}
Expand Down Expand Up @@ -519,6 +564,35 @@ function usual(&$out) {
else $info = $dev->data;
} else $info = 'Что-то пошло не так...';

echo $info;
exit;
} else if ($op == 'test_api_cmd') {

$dip = $_GET['dip'];
$dtoken = $_GET['dtoken'];
$cmd = $_GET['dcmd'];
$opt = $_GET['dopt'];

header("HTTP/1.0: 200 OK\n");
header('Content-Type: text/html; charset=utf-8');

if (!class_exists('miIO', false)) {
include_once(DIR_MODULES . 'xiaomimiio/lib/miio.class.php');
}
$this->getConfig();

if ($miio_module->config['API_IP']) $bind_ip = $miio_module->config['API_IP'];
else $bind_ip = '0.0.0.0';
if ($miio_module->config['API_LOG_MIIO']) $miio_debug = true;
else $miio_debug = false;

$dev = new miIO($dip, $bind_ip, $dtoken, $miio_debug);

if ($dev->msgSendRcv($cmd, $opt, time())) {
if ($dev->data == '') $info = 'Результат выполнения команды не получен. Вероятно, указан неверный токен.';
else $info = $dev->data;
} else $info = 'Что-то пошло не так...';

echo $info;
exit;
}
Expand Down Expand Up @@ -602,7 +676,7 @@ function propertySetHandle($object, $property, $value) {
//что может быть неприемлемо.
//$this->requestStatus($properties[$i]['DEVICE_ID']);
} elseif ($properties[$i]['TITLE'] == 'power') {
// Команда на включение и выключени
// Команда на включение и выключение
if ($value) {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_power', '["on"]');
} else {
Expand All @@ -620,6 +694,27 @@ function propertySetHandle($object, $property, $value) {
if ($value < 1) $value = 1;
if ($value > 100) $value = 100;
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_cct', "[$value]");
} elseif ($properties[$i]['TITLE'] == 'ct') {
// Команда на изменение цветовой температуры (в кельвинах от 1700 до 6500)
$value = (int)$value;
if ($value < 1700) $value = 1700;
if ($value > 6500) $value = 6500;
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_ct_abx', '[' . $value . ',"sudden",200]');
} elseif ($properties[$i]['TITLE'] == 'rgb') {
// Команда на изменение цвета RGB (от 0 до 16777215)
// RGB = (R*65536)+(G*256)+B, где R, G и B десятичные значения от 0 до 255.
$value = preg_replace('/^#/', '', $value);
$val = hexdec($value);
if ($val != 0 && $val < 16777216) {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_rgb', '[' . $val . ',"smooth",100]');
}
} elseif ($properties[$i]['TITLE'] == 'wifi_led') {
// Команда на включение и выключение индикатора wifi
if ($value) {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_wifi_led', '["on"]');
} else {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_wifi_led', '["off"]');
}
}

if($properties[$i]['DEVICE_TYPE'] == 'lumi.gateway.v3') {
Expand Down Expand Up @@ -702,7 +797,7 @@ function processCommand($device_id, $command, $value, $params = 0) {
/**
* processMessage
*
* ...
* Обработка ответов от устройств
*
* @access private
*/
Expand Down Expand Up @@ -805,6 +900,9 @@ function processMessage($message, $command, $device_id) {
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
if ($key == 'rgb') {
$value = str_pad(dechex($value), 6, '0', STR_PAD_LEFT);
}
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
Expand All @@ -828,13 +926,62 @@ function processMessage($message, $command, $device_id) {
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'philips.light.ceiling' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_PHILIPS_LIGHT_CEILING_PROPS);
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'yeelink.light.ceiling1' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_YEELIGHT_CEILING_LIGHT_PROPS);
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'yeelink.light.lamp1' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_YEELIGHT_LAMP_LIGHT_PROPS);
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'yeelink.light.strip1' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_YEELIGHT_STRIP_PROPS);
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
if ($key == 'rgb') {
$value = str_pad(dechex($value), 6, '0', STR_PAD_LEFT);
}
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'zimi.powerstrip.v2' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_ZIMI_POWERSTRIP_2_PROPS);
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
if ($key == 'current' || $key == 'power_consume_rate') {
if ($value == '' || $value == 'null' || $value == null) $value = '0.00';
}
if ($key == 'mode') {
if ($value == 'null' || $value == null) $value = '';
}
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
}
}

foreach ($res_commands as $c) {
$cmd = $c['command'];
$val = $c['value'];
if ($cmd == 'power') {
if ($cmd == 'power' || $cmd == 'wifi_led') {
if ($val == 'on') $val = 1;
else if ($val == 'off') $val = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/cycle_xiaomimiio.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Xiaomi miIO Cycle
* @author <[email protected]>
* @copyright 2017 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 0.7b
* @version 0.8b
*/

chdir(dirname(__FILE__) . '/../');
Expand Down
4 changes: 2 additions & 2 deletions templates/xiaomimiio/action_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ <h4 class="modal-title">Xiaomi miIO</h4>
<div class="modal-body">
<div class="float-right">
<img src="../templates/xiaomimiio/milogo.png" width="48" height="48">
<br><br><p><b>v.0.7b</b></p>
<br><br><p><b>v.0.8b</b></p>
</div>
<p class="float-left">
Модуль поддержки Wi-Fi устройств из экосистемы Xiaomi Mihome, взаимодействующих по протоколу miIO. <br><br>
Обсуждение модуля на <a href="http://majordomo.smartliving.ru/forum/" target="_blank">форуме</a>.<br>
Обсуждение модуля на <a href="https://majordomo.smartliving.ru/forum/viewtopic.php?f=5&t=4863" target="_blank">форуме</a>.<br>
Проект на <a href="https://github.com/skysilver-lab/majordomo-xiaomimiio" target="_blank">Github</a>.<br>
Проект в <a href="https://connect.smartliving.ru/tasks/51.html" target="_blank">Connect</a>.<br>
</p>
Expand Down
Binary file added templates/xiaomimiio/img/small/chuangmi.ir.v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions templates/xiaomimiio/miio_devices_edit_default.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<fieldset>
[#if ID=""#]
<legend><#LANG_NEW_RECORD#></legend>
<legend>Новое устройство</legend>
[#endif ID#]

<div class="form-group">
Expand Down Expand Up @@ -43,12 +43,18 @@
<option value=""></option>
<option value="lumi.gateway.v3" [#if DEVICE_TYPE="lumi.gateway.v3"#] selected[#endif#]>Mi Smart Home Gateway 2</option>
<option value="chuangmi.plug.m1" [#if DEVICE_TYPE="chuangmi.plug.m1"#] selected[#endif#]>Mi Smart Socket Plug 2</option>
<option value="zimi.powerstrip.v2" [#if DEVICE_TYPE="zimi.powerstrip.v2"#] selected[#endif#]>Mi Smart Power Strip 6 Plugs</option>
<option value="isa.camera.isc5" [#if DEVICE_TYPE="isa.camera.isc5"#] selected[#endif#]>Mi Square Smart Camera</option>
<option value="rockrobo.vacuum.v1" [#if DEVICE_TYPE="rockrobo.vacuum.v1"#] selected[#endif#]>Mi Vacuum Cleaner</option>
<option value="philips.light.sread1" [#if DEVICE_TYPE="philips.light.sread1"#] selected[#endif#]>Philips EyeCare Smart Lamp 2</option>
<option value="yeelink.light.lamp1" [#if DEVICE_TYPE="yeelink.light.lamp1"#] selected[#endif#]>Mi LED Desk Lamp</option>
<option value="chuangmi.ir.v2" [#if DEVICE_TYPE="chuangmi.ir.v2"#] selected[#endif#]>Mi IR Remote 360</option>
<option value="philips.light.sread1" [#if DEVICE_TYPE="philips.light.sread1"#] selected[#endif#]>Philips EyeCare Smart Desk Lamp 2</option>
<option value="philips.light.ceiling" [#if DEVICE_TYPE="philips.light.ceiling"#] selected[#endif#]>Philips EyeCare Smart Ceiling Lamp</option>
<option value="philips.light.bulb" [#if DEVICE_TYPE="philips.light.bulb"#] selected[#endif#]>Philips Light Bulb</option>
<option value="yeelink.light.color1" [#if DEVICE_TYPE="yeelink.light.color1"#] selected[#endif#]>Yeelight Color Bulb</option>
<option value="yeelink.light.mono1" [#if DEVICE_TYPE="yeelink.light.mono1"#] selected[#endif#]>Yeelight White Bulb</option>
<option value="yeelink.light.ceiling1" [#if DEVICE_TYPE="yeelink.light.ceiling1"#] selected[#endif#]>Yeelight Ceiling Light</option>
<option value="yeelink.light.strip1" [#if DEVICE_TYPE="yeelink.light.strip1"#] selected[#endif#]>Yeelight LED Lightstrip</option>
</select>
</div>
</div>
Expand Down
Loading

0 comments on commit e80ceda

Please sign in to comment.