ws2812_Domoticz+esp8266_esp_easy_ws2812RGB灯(NeoPixel) 折腾记录

@[TOC](ws2812_Domoticz+esp8266_esp_easy_ws2812RGB灯(NeoPixel) 折腾记录)
RGB_

Esp8266:

ESP8266 刷 Esp_Easy 固件,并设定NeoPixel 如下图所示

ws2812_Domoticz+esp8266_esp_easy_ws2812RGB灯(NeoPixel) 折腾记录_第1张图片

在domoticz 中添加虚拟硬件,并创建虚拟传感器 RGB 灯

ws2812_Domoticz+esp8266_esp_easy_ws2812RGB灯(NeoPixel) 折腾记录_第2张图片

在设置中查看创建的虚拟传感器RGB 灯的IDX 并记录下来,转到 开关 面板 找到RGB 灯开关 分别编辑 开触发命令 和关触发命令

// ON
script:///opt/domoticz/scripts/python/ow12.py
// OFF
http://<esp_easy IP>/control?cmd=NeoPixelAll,0,0,0

ws2812_Domoticz+esp8266_esp_easy_ws2812RGB灯(NeoPixel) 折腾记录_第3张图片

编写控制脚本并赋予执行权限

脚本来源于 Domoticz论坛

// /opt/domoticz/scripts/python/ow12.py
# vim /opt/domoticz/scripts/python/ow12.py
  1 #!/usr/bin/env python
  2
  3 import requests
  4 import ast
  5IDX
  6 ID = '刚刚创建的RGB 传感器设备IDX'
  7
  8 domo_url = "http://domoticzIP:port/json.htm?type=devices&rid={}".format(ID)
  9 owl_control_url = 'http://ESP_easy IP /control?cmd=NeoPixelAll,{},{},{}'
 10
 11 def app():
 12     data = requests.get(domo_url)
 13     print (data)
 14     colour_data = ast.literal_eval(data.json()['result'][0]['Color'])
 15     level_data = data.json()['result'][0]['Level']
 16     state = data.json()['result'][0]['Data']
 17     red = int(colour_data["r"])
 18     green = int(colour_data["g"])
 19     blue = int(colour_data["b"])
 20     level = int(level_data)
 21
 22     redl = int((red/100) * level)
 23     greenl = int((green/100) * level)
 24     bluel = int((blue/100) * level)
 25
 26     if state == 'Off':
 27         redl = 0
 28         greenl = 0
 29         bluel = 0
 30
 31     #send to light
 32     _i = requests.get(url=owl_control_url.format(redl,greenl,bluel))
 33
 34
 35 if __name__ == "__main__":
 36     print (domo_url)
 37     app()
//添加可执行权限
# chmod +x  /opt/domoticz/scripts/python/ow12.py

参考来源:
Python script for full rgb + brightness control of easyESP neopixel

你可能感兴趣的:(Linux)