[ESP8266] Commercial H801 WiFi RGB-dimmer topic

Everything about esp8266 and more.

Moderator: leecollings

ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

[ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

Like i posted in Cheap WiFi LED dimmer (~10$), the Chinese people are now using a ESP8266 in a commercial available WiFi dimmer.
ThinkPad wrote:So, the Chinese people are now using the ESP8266 in commercial products: http://hackaday.com/2015/08/25/esp8266- ... -products/
Direct link to product: http://aliexpress.com/item/rgb-WiFi-con ... 23622.html "Huacanxing H801 WiFi"
I received mine today, and it works nicely with the 'LEDDimmer.apk' app.
For those who don't know the device: it is a RGB-dimmer through WiFi, based on the popular ESP8266 chip. In the default mode it presents itself as an accespoint and you connect your phone to it.
H801WiFi(1).png
H801WiFi(1).png (81.34 KiB) Viewed 39249 times
Productpage (translated from Chinese > English) (also saved PDF-file as mirror, attached to this post).

However, instead of connecting my Android phone to the accespoint-mode of this dimmer, i ofcourse would like to connect it to Domoticz 8-)
But how? The code from Quindor' is only for a single monochrome LED-strip. How can we convert this to RGB, so we have a nice colorpicker inside Domoticz?

Maybe use the current firmware and try to mimick the app behaviour with something like 'netcat' to send raw socket commands? I will try to connect the box to my WiFi soon and see if i can sniff the traffic with Wireshark

By the way i put the app online here because i couldn't find it anywhere on the internet, i got this copy by mail from the seller when i asked him about it. Sorry, link is down, don't have the app anymore :( Search for "LEDDimmer.apk" or ask the seller.
Attachments
H801_WiFi_Dimmer.pdf
(1.02 MiB) Downloaded 2178 times
I am not active on this forum anymore.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

Ok, i got the extra accespoint setup and connected the ESP box to it. I can now sniff anything that is being sent from/to the device :twisted:
I already discovered that the commands are sent over UDP, port 30977 (from 30978)
By using this filter in Wireshark:

Code: Select all

udp.port eq 30978 and udp.port eq 30977
New lines are added to the screen everytime a command is sent to the box.

Setting the red channel to max: fbebff0000000079979d00
Setting the red channel to zero: fbeb000000000079979d00

So the first value after the 'fbeb' changes to 'FF', which equals to 255 :mrgreen:

Setting the green channel from zero to max shows fbeb00ff00000079979d00
Setting the blue channel from zero to max shows fbeb0000ff000079979d00

If i set it to '124' through the app, it is shown as '7c'. So it seems all the values are converted from decimal (in the app), to hex (UDP packet).

So the protocol seems very easy actually..... I am now trying to send these packets myself, with sendip, but that isn't working yet.

Code: Select all

sendip -p ipv4 -is 192.168.4.15 -p udp -us 30978 -ud 30977 -d fbeb000000000079979d00 -v 192.168.4.131
That should turn the red channel to max. Raspberry (source) is .15 and the ESP dimmer (destination) is .131

However, the data of that line of code is seen as '66626562303030303030303030303739393739643030' by Wireshark..... i am stuck now :mrgreen:

I also tried this:

Code: Select all

echo -n "fbebff0000000079979d00" | nc -4u -w1 192.168.4.131 30977
but that didn't generate any logging in Wireshark. Also tried changing the 192.168.4.131 into 192.168.4.255 but no luck (and no output in Wireshark) either.
I am not active on this forum anymore.
User avatar
jvdz
Posts: 2282
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by jvdz »

Shouldn't you define the -d as hex by using?:

Code: Select all

-d 0xfbeb000000000079979d00
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

jvdz wrote:Shouldn't you define the -d as hex by using?:

Code: Select all

-d 0xfbeb000000000079979d00
Jos
Spoiler: show
Image
That did the trick 8-)

What's very cool, is that i can pick a color from here: http://www.rapidtables.com/web/color/RGB_Color.htm , look at the 6-digit hex value, put it into to my syntax, drop it into my commandline and my LED-strip changes to that color :D
Change the red part to the hex value of that website and it works
sendip -p ipv4 -is 192.168.4.15 -p udp -us 30978 -ud 30977 -d 0xfbeb000000000079979d00 -v 192.168.4.131

But now, how to get this in Domoticz :D And maybe 'translate' it to 'netcat', because that is a more common utility than 'sendip'.

Other commands:
Spoiler: show
On:

Code: Select all

0xfbebff003c000079979d00
(sent 6 times by app, only works when controler is set to '00 Static state' mode in app)

Off:

Code: Select all

0xfbeb000000000079979d00
(sent 6 times by app, only works when controler is set to '00 Static state' mode in app)

To get it back from the disco-mode programs into the mode where it accepts colors from the colorpicker-wheel:

Code: Select all

0xfbec001e00000079979d00
(sent 2 times by app)



It also has two channels for white LED's, called 'W1' and 'W2' in the app & on the box. It can be used by VCC + W1 and VCC + W2

Channel W1 to max

Code: Select all

0xfbeb000000ff0079979d00
Channel W1 to zero

Code: Select all

0xfbeb000000000079979d00
Channel W2 to max

Code: Select all

0xfbeb00000000ff79979d00
Channel W2 to zero

Code: Select all

0xfbeb000000000079979d00
So if you want to have half the brightness (50%) you can lookup the value (255 is max, the half of it is about 128) here: http://ascii.cl/conversion.htm and see that you need to fill in hex-value 80 instead of the ff
H801proto.PNG
H801proto.PNG (6.6 KiB) Viewed 39205 times
I must say, this is a preeeeetttty nice little device for $10 8-)
I am not active on this forum anymore.
richardtrip
Posts: 5
Joined: Wednesday 09 September 2015 21:12
Target OS: -
Domoticz version:
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by richardtrip »

ThinkPad wrote:
jvdz wrote:Shouldn't you define the -d as hex by using?:

Code: Select all

-d 0xfbeb000000000079979d00
Jos
Spoiler: show
Image
That did the trick 8-)

What's very cool, is that i can pick a color from here: http://www.rapidtables.com/web/color/RGB_Color.htm , look at the 6-digit hex value, put it into to my syntax, drop it into my commandline and my LED-strip changes to that color :D
Change the red part to the hex value of that website and it works
sendip -p ipv4 -is 192.168.4.15 -p udp -us 30978 -ud 30977 -d 0xfbeb000000000079979d00 -v 192.168.4.131

But now, how to get this in Domoticz :D And maybe 'translate' it to 'netcat', because that is a more common utility than 'sendip'.

Other commands:
Spoiler: show
On:

Code: Select all

0xfbebff003c000079979d00
(sent 6 times by app, only works when set to '00 Static state' mode in app)

Off:

Code: Select all

0xfbeb000000000079979d00
(sent 6 times by app, only works when set to '00 Static state' mode in app)

To get it back from the disco-mode programs into the mode where it accepts colors from the colorpicker-wheel:

Code: Select all

0xfbec001e00000079979d00
(sent 2 times by app)



It also has two channels for white LED's, called 'W1' and 'W2' in the app & on the box. It can be used by VCC + W1 and VCC + W2

Channel W1 to max

Code: Select all

0xfbeb000000ff0079979d00
Channel W1 to zero

Code: Select all

0xfbeb000000000079979d00
Channel W2 to max

Code: Select all

0xfbeb00000000ff79979d00
Channel W2 to zero

Code: Select all

0xfbeb000000000079979d00
So if you want to have half the brightness (50%) you can lookup the value (255 is max, the half of it is about 128) here: http://ascii.cl/conversion.htm and see that you need to fill in hex-value 80 instead of the ff
H801proto.PNG
I must say, this is a preeeeetttty nice little device for $10 8-)
You can create a couple of dimmers (3 for rgb and 2 for the white channels) and work out some lua magic to convert the dimmer level to hex and push the value on every change.
tweaker
Posts: 10
Joined: Monday 24 August 2015 15:35
Target OS: -
Domoticz version:
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by tweaker »

cool stuff!! Would it be possible to get the ESP Easy firmware into this box? Connecting to Domoticz may then be a lot easier.
I already have two ESP's running with ESP Easy and it would be nice if all Wifi devices have the same simple interface.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

richardtrip wrote:
ThinkPad wrote:
jvdz wrote:[...]
[...]

But now, how to get this in Domoticz :D And maybe 'translate' it to 'netcat', because that is a more common utility than 'sendip'.
[...]
You can create a couple of dimmers (3 for rgb and 2 for the white channels) and work out some lua magic to convert the dimmer level to hex and push the value on every change.
Luckily for me, 'Quindor' has already done something like that for a white LED-strip: http://domoticz.com/forum/viewtopic.php?f=38&t=4723
I will have a try to see if i can get it working with three sliders (R, G, B). But i see the MiLight/Limitless hardware gives you a colorpicker in Domoticz: http://i60.tinypic.com/2mqnsjr.png
A nice colorpicker is ofcourse preferred.
Best would be if i could grab that value through a Lua script..... but how?
tweaker wrote:cool stuff!! Would it be possible to get the ESP Easy firmware into this box? Connecting to Domoticz may then be a lot easier.
I already have two ESP's running with ESP Easy and it would be nice if all Wifi devices have the same simple interface.
Yes. If you have watched the video on Hackaday, you will see that the board has pads for RX/TX/GND/VCC and a jumper. If you solder headers on, you can put it into programming mode (by shorting the jumper) and upload your own firmware.

However, i will stick with this default firmware, because it works very good actually. The usage of the HEX-colorcodes is quite pleasant, and also the device works smoothly now. I only have to find a way to use it with Domoticz.

I have found this post: http://domoticz.com/forum/viewtopic.php ... 829#p47829 , that dimmer seems to use the same kind of approach. I will try if i can send commands to my dimmer with netcat/telnet (last is preferred as it is available by default on my NAS) this afternoon.
I am not active on this forum anymore.
richardtrip
Posts: 5
Joined: Wednesday 09 September 2015 21:12
Target OS: -
Domoticz version:
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by richardtrip »

You can check the lua script for the hue on how to read the dummy dimmer values : https://www.domoticz.com/wiki/Philips_Hue_Lights
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

richardtrip wrote:You can check the lua script for the hue on how to read the dummy dimmer values : https://www.domoticz.com/wiki/Philips_Hue_Lights
Thank you, will see if i can use that. I also found a PHP-script to control a Onkyo 5.1 receiver: http://gathering.tweakers.net/forum/lis ... 0#44532360
I will try to modify that to send UDP-packets to the wifi dimmer, so that i can do something like this: http://ip/rgbdimmer.php?color=ff8d00

I think it should be something like this:

Code: Select all

<?php
  $color = $_GET["hex"] //Call the script like rgb.php?hex=ff8d00
  $red = substr($color, 0, 2);
  $green = substr($color, 2, 2);
  $blue = substr($color, 4, 2);
  $fp = pfsockopen("udp://192.168.4.131", "30977");
  //Color should be like 0xfbebRRGGBB000079979d00 (where RR, GG, BB are the hex values for the colors)
  $line="\xfb\xeb\x{$red}\x{$green}\x{$blue}\x00\x00\x79\x97\x9d\x00";
  //Or maybe $line should be like this:
  //$line="0xfbeb{$red}{$green}{$blue}000079979d00";
  fwrite($fp, $line);
  fclose($fp);
?>
Not at home now, so can't try.

Combined with a HTML page with a colorpicker this would make the dimmer controllable via PC. For Domoticz a Lua-script would be better i think. Or just make scenes for the colors most used, is a bit easier :lol:
I am not active on this forum anymore.
mvdbro
Posts: 24
Joined: Saturday 31 January 2015 19:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by mvdbro »

tweaker wrote:cool stuff!! Would it be possible to get the ESP Easy firmware into this box? Connecting to Domoticz may then be a lot easier.
Maybe this can be done. But first I have to figure out how we could control such a RGB device from Domoticz.

(I'm fairly new to Domoticz, so this is my first attempt :mrgreen: :mrgreen: )

What I've done so far:
===================
1) Create a new virtual sensor, type RGB Switch (this is the only one I could select and looking like a RGB dimmer device)
2) Added MQTT Client Gateway with LAN interface to Domoticz
3) Use MQTTfx tool to listen to domoticz/out messages.

It sends messages like this when I click on the color 'box' from within the device:

Code: Select all

{
   "Battery" : 255,
   "RSSI" : 12,
   "dtype" : "Lighting Limitless/Applamp",
   "id" : "00082247",
   "idx" : 249,
   "name" : "Unknown",
   "nvalue" : 15,
   "stype" : "RGB",
   "unit" : 1
}
Hmmm, how to get RGB data from this?

Other options
============
Maybe we can use http action for this device, but can I use some 'variables' to substitute and do something like this:

Code: Select all

http://<dimmmer ip>/control?cmd=pwm,%red%,%green%,%blue%
Where the %red%, %green%, %blue% are substituted by Domoticz before the request is send.

That could also work. Getting the querystring pairvalues into the ESP and send them out on 3 PWM GPIO's should do the trick...

Maybe someone could help me here?
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

I got some help from a friendly member of Tweakers.net, and it is now working :mrgreen:

rgb.php
Spoiler: show

Code: Select all

<?php
//Script made by 'ThinkPad' for 'H801 WiFi dimmer' (based on ESP8266)
//See forumthread at http://domoticz.com/forum/viewtopic.php?f=38&t=7957
//Save as 'rgb.php' and call the script like rgb.php?hex=ff8d00

$host = 'udp://192.168.4.23';    
$port = 30977; 

//Strip out any invalid characters, only A-Z and numbers are allowed.
$color = preg_replace("/[^a-zA-Z0-9\s]/", "", $_GET["hex"]);

//Check if the colorcode sent has 6 values
if ( strlen($color) == 6 ) {
	$red = substr($color, 0, 2);
	$green = substr($color, 2, 2);
	$blue = substr($color, 4, 2);

	$fp = pfsockopen($host, $port);

//Color should be like 0xfbebRRGGBB000079979d00 (where RR, GG, BB are the hex values for the colors)
	$line="\xfb\xeb" . chr(hexdec($red)) . chr(hexdec($green)) .  chr(hexdec($blue)) . "\x00\x00\x79\x97\x9d\x00";
	fwrite($fp, $line);
	fclose($fp);

	echo  '<body bgcolor="#'. $color .'">';  
	echo 'Chosen color is: <a href="http://www.color-hex.com/color/' . $color . '"><b>' . $color . '</b></a>';
}
else {
	echo "Not a valid colorcode, has to be 6 characters!";
}


//Check if rgb.php?cmd=PWRON was received
if ($_GET["cmd"] == "PWRON"){
	$fp = pfsockopen($host, $port);
$line_on="\xfb\xeb\xff\x00\x3c\x00\x00\x79\x97\x9d\x00"; //Power on
$line_normalmode="\xfb\xec\x00\x1e\x00\x00\x00\x79\x97\x9d\x00"; //Set controller into mode to accept colorcodes

$x = 1;

//Send 'power on' command 6 times
while($x <= 6) {
	fwrite($fp, $line_on);
	fclose($fp);
	$x++;
} 

//Send 'back to colorcode-mode' command 3 times
while($x <= 3) {
	fwrite($fp, $line_normalmode);
	fclose($fp);
	$x++;
} 

}

//Check if rgb.php?cmd=PWROFF was received
if ($_GET["cmd"] == "PWROFF"){
	$fp = pfsockopen($host, $port);
$line_off="\xfb\xeb\x00\x00\x00\x00\x00\x79\x97\x9d\x00"; //Power off

//Send 'power off' command 6 times
while($x <= 6) {
	fwrite($fp, $line_off);
	fclose($fp);
	$x++;
} 

}

?>
Script got a little bit big, but now i'm sure nothing strange will happen, because i implemented a few checks.

I also made a small page where a color can be picked and sent to the controller:
Spoiler: show

Code: Select all

<html>
<head>
<title>Colorpicker</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
	var field1 = $('#hexcolorcode');
	$('#send').click(function(){
		if(!field1.val()){
			alert("Please enter a value");
			field1.focus();
			return;
		}
		jQuery.ajax({
			url: 'rgb.php',
			type: 'get',
			data: 'hex=' + field1.val()
		});
	});
});
</script>
</head>
<body>
<body>
<script type="text/javascript" src="jscolor/jscolor.js"></script>

Click here: <input class="color" id="hexcolorcode" value="66ff00">	
<input type="button" value="Submit" id="send">
</body>
</body>
</html>
It uses 'jscolor' colorpicker: http://jscolor.com/try.php

For scripting: this commandline command also works:

Code: Select all

echo -e '\xfb\xeb\xf0\x00\xff\x00\x00\x79\x97\x9d\x00' | nc -u -w1 192.168.4.23 30977
Might be useful for a Lua-script later on.
I am not active on this forum anymore.
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

So, am i the only one on this forum with this cool device :roll: ?
It's only 10 bucks and has 5 channels (R, G, B + white1 + white2) :D
I am not active on this forum anymore.
erik
Posts: 4
Joined: Tuesday 07 April 2015 17:54
Target OS: Linux
Domoticz version: V2.3191
Location: Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by erik »

Looks like a way better solution then the MySensor rgb dimmer, isn't it?
evertide
Posts: 14
Joined: Wednesday 19 November 2014 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by evertide »

Hi all,

Indeed a great and cheap Wi-Fi dimmer and thanks Thinkpad and others for the information to integrate this into Domoticz.
The packet layout is a tad different as the picture above in the forum. The 3 hex numbers in the package are the led dimmer Mac address in the form of MAc6:MAc5:Mac4. this with a trailer 00 to close the package.
After the last 00 hex another MAC address can be added if you address the dimmers in a broadcast ( 192.168.2.255). I have added a explaining picture.

I also attach my code how I integrated these led dimmers in domoticz. Integration is done by creating a virtual on/off switch with the main ( almost always used) color code and some scene's to change them to another color.
Since I run stable I have not bothered yet with the RGB pop switch. however I presume this together with a LUA script can interact as well for full rgb color selection.

Code: Select all

#!/bin/bash
#########
#
# Bash remote script for controlling H801 WiFi led controller
# version 0.3 Evert
#
# dependency fping and netcat (nc)
# format hex string to led dimmer for color "fbeb RRGGBB WW(1) WW(2) MM(6) MM(5) MM(4) 00 " ( for multiple add                                                                                                                                the next 3 MAC otects MM(6) MM(5) MM(4) 00
# where "fbeb" is  rgb color and "fbec" is fixed modes
# RR=Red, GG=Green, BB=Blue, WW(1)=White1, WW(2)=White2,  MM(6)=Mac octet 6, MM(5)=Mac octet 5, MM(4)=Mac octe                                                                                                                               t4
# e.g fbeb00000000005c979d00ad1a0200 or fbeb00000000005c979d00
# Input script example h801-leddimmer.sh 192.168.2.121 ad1a02 264 rgbww ff20000a00




#########

#
# Init
# Domoticz server

DOMO_SERVER="192.168.2.176"


#
## Functions
#

errormsg ()  {
                loggerall "###### H801 WiFi controller script error message"
                loggerall "# Script options are on, off, comfort, relax, reading, energize, concentrate, fun m                                                                                                                               onochromelight, and rgbww RRGGBBW1W2"
                loggerall "# When RRGGBBW1W2 is used RR is red in hex notation, GG is green, BB is Blue, W1 is                                                                                                                                white1 and W2 is white e.g rgbww 1213145000"
                loggerall "# When fun is used options are fullcolor, monochromeshade, monochromefade, monochro                                                                                                                               melight, mixedcolorshade, mixedcolorfade,"
                loggerall "# mixedcolorlight, redfade, greenfade, bluefade, monochrometransition, mixedcolortr                                                                                                                               ansistion, sevencolortransistion"
                loggerall "# Input script example h801-leddimmer.sh 192.168.2.121 ad1a02 264 rgbww ff20000a00"
                loggerall "#"
                loggerall "# Input recieved was : $1 $2 $3 $4 $5"
                loggerall "#"
                loggerall "######"
}

loggerall ()  {
                logger $1
                echo $1
}


checkalive () {
                loggerall  "Checking host alive $1"

                fping -c2 -t300 $IP 2>/dev/null 1>/dev/null #fping is not a standard packages and needs to be                                                                                                                                instaled

                if  [ "$?" = 0 ]
                    then
                        loggerall "Host $1 was found alive"
                    else
                        errormsg $1
                        loggerall "Host $1 was not found alive ( is fping installed)"
                        exit 1
                fi
}

onofffunction ()  {
                loggerall "Switching $1 $2"

                #Set in rgb accept mode ( twice to make sure....)
                #Set normalmode="fbec000100000079979d00" (example)
                FULLRGBWW=fbec0001000000$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #Set a color to let the power off/on work after the set mode
                FULLRGBWW=fbebff20000a00$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #The real on off command
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  if [ $2 = "off" ]; then FULLRGBWW=fbeb0000000000$MACTOTAL; echo -ne "$(echo $FULLRGBWW | sed                                                                                                                                -e 's/../\\x&/g')" | nc -u -w1 $1 30977; fi
                  if [ $2 = "on" ];  then FULLRGBWW=fbebff20000a00$MACTOTAL; echo -ne "$(echo $FULLRGBWW | sed                                                                                                                                -e 's/../\\x&/g')" | nc -u -w1 $1 30977; fi
                 let COUNTER=COUNTER+1
                done

                #Update domoticz
                if [ $2 = "on" ] ; then CMD=1 ; fi
                if [ $2 = "off" ] ; then CMD=0 ; fi

                curl --request GET "http://$DOMO_SERVER/json.htm?type=command&param=udevice&idx=$DOMOIDX&nvalu                                                                                                                               e=$CMD"&


}


rgbwwfunction ()  {
                loggerall "Switching $1 in rgbww $2"

                #Set in rgb accept mode
                #Set normalmode="fbec001e00000079979d00"
                FULLRGBWW=fbec0001000000$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #Set the rgb value
                FULLRGBWW=fbeb$2$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                curl --request GET "http://$DOMO_SERVER/json.htm?type=command&param=udevice&idx=$DOMOIDX&nvalu                                                                                                                               e=1"&


}

funfunction () {
                loggerall "Switching $1 in fun $2"
                #Set in in specific mode
                SPECIALRGBWW=fbec$2$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  echo -ne "$(echo $SPECIALRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                curl --request GET "http://$DOMO_SERVER/json.htm?type=command&param=udevice&idx=$DOMOIDX&nvalu                                                                                                                               e=1"&
}


#
## Check and process input
#

#Check if a minimum one input supplied
if [[ $# -lt 4 ]] #Check to see if at least one parameter is supplied
    then
        errormsg $1 $2 $3 $4 $5
        loggerall "Error: A minimum of four inputs please"
        exit 1
fi


#Check that first input is valid IPv4 IP address and alive
#Declare IP variable
if [[  "$(echo $1 | grep '[0-9]\{1,3\}[.][0-9]\{1,3\}[.][0-9]\{1,3\}[.][0-9]\{1,3\}')" ]]
   then
      loggerall "Ip address used '$1' "
      IP=$1
      checkalive $IP
   else
      errormsg $1 $2 $3 $4 $5
      loggerall "Ip address not valid '$1'"
      exit 1
fi


#Declare second input as led dimmer mac address id
if [[ ! $2 =~ ^-?[0-9a-fA-F]+$ ]] #Check to see if only numbers and characters a till f (hex) are supplied
    then
        errormsg $1 $2 $3 $4 $5
        loggerall "Error: Mac address address in format Mac6 MAC5 MAC4 in hex"
        exit 1
    else
        MACTOTAL=$2
        declare -l MACTOTAL
        MACTOTAL=$MACTOTAL"00" #adding the trailing 00 as well
fi


#Declare the third input as DOMOIDX
if [[ ! $3 =~ ^-?[0-9]+$ ]]
   then
      errormsg $1 $2 $3 $4 $5
      loggerall "Error: Domoticz idx must be a number"
      exit 1
   else
      DOMOIDX=$3
fi

#Declare  fourth input as variable MODUS all lowercase
if [[ ! $4 =~ ^-?[a-zA-Z]+$ ]] #Check to see if only characters are supplied
    then
        errormsg $1 $2 $3 $4 $5
        loggerall "Error: Mode input should only be characters"
        exit 1
    else
        MODUS=$4
        declare -l MODUS # Define lower case
        MODUS=$MODUS
fi

#Make sure that if rgbww or fun is selected as modus a 5th input is there
if [[ $4 = "rgbww" && $5 = "" ]] || [[ $4 = "fun" && $5 = "" ]]
   then
      errormsg $1 $2 $3 $4 $5
      loggerall "Error: If rgbww or fun is the input a second input is required"
      exit 1
fi


#Declare fith  input as RGBWW if fourth input is rgbww
if [[  $MODUS = "rgbww" && ! $5 = "" ]]
   then
       if [[ ! $5 =~ ^-?[0-9a-fA-F]+$ ]] #Check to see if only numbers and characters a till f are supplied
          then
              errormsg $1 $2 $3 $4 $5
              loggerall "Error: rgb w1 w2 value can only be hex numbers"
              exit 1
          else
              if [[ ! ${#5} = 10 ]] # Check that input string is 10 long
                 then
                     errormsg $1 $2 $3 $4 $5
                     loggerall "Error: rgb w1 w2 must be 10 hex numbers"
                     exit 1
                 else
                     RGBWW=$5
                     declare -l RGBWW
                     RGBWW=$RGBWW
              fi
       fi
fi

#Declare fith input as SPECIALMODE if fourth input is fun
if [[  $MODUS = "fun" && ! $5 = "" ]]
   then
       if [[ ! $5 =~ ^-?[a-zA-Z]+$ ]] #Check to see if characters (a till z) are supplied
           then
               errormsg $1 $2 $3 $4 $5
               loggerall "Error: With the argument fun there must be a specialmode defined"
               exit 1
           else
               SPECIALMODE=$5
               declare -l SPECIALMODE
               SPECIALMODE=$SPECIALMODE
       fi
fi

#######################
#
## Program
#
#######################


case "$MODUS:$SPECIALMODE" in

  "-?":*)                       errormsg                        ;;

## begin list of commands.

  "on":*)                        onofffunction $IP on            ;;
  "off":*)                       onofffunction $IP off           ;;
  "comfort":*)                   rgbwwfunction $IP ff20000a00    ;;
  "relax":*)                     rgbwwfunction $IP c8fa002000    ;;
  "reading":*)                   rgbwwfunction $IP f2f2f20000    ;;
  "energize":*)                  rgbwwfunction $IP 00d0ff0000    ;;
  "concentrate":*)               rgbwwfunction $IP 00c5db0000    ;;
  "rgbww":*)                     rgbwwfunction $IP $RGBWW        ;;
  "fun":"monochromeshade")       funfunction   $IP 0201000000    ;;
  "fun":"monochromefade")        funfunction   $IP 0301000000    ;;
  "fun":"monochromelight")       funfunction   $IP 0401000000    ;;
  "fun":"mixedcolorshade")       funfunction   $IP 0501000000    ;;
  "fun":"mixedcolorfade")        funfunction   $IP 0601000000    ;;
  "fun":"mixedcolorlight")       funfunction   $IP 0701000000    ;;
  "fun":"redfade")               funfunction   $IP 0801000000    ;;
  "fun":"greenfade")             funfunction   $IP 0901000000    ;;
  "fun":"bluefade")              funfunction   $IP 0a01000000    ;;
  "fun":"monochrometransition")  funfunction   $IP 0b01000000    ;;
  "fun":"mixedcolortransistion") funfunction   $IP 0c01000000    ;;
  "fun":"sevencolortransistion") funfunction   $IP 0d01000000    ;;


  *:*)                          errormsg
                                loggerall "Error: no valid input for mode recieved"                                                                                                                                                            ;;


esac

echo done
exit 0
Attachments
led-dimmer packet layout.jpg
led-dimmer packet layout.jpg (20.03 KiB) Viewed 38229 times
Led dimmer addressing.jpg
Led dimmer addressing.jpg (32.08 KiB) Viewed 38229 times
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

Nice work evertide! I still haven't connected my H801 dimmer yet, lack of time :P

Your script seems complicated, how do you call it from Domoticz? 'script.sh fun:greenfade' or something?
I am not active on this forum anymore.
evertide
Posts: 14
Joined: Wednesday 19 November 2014 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by evertide »

HI,

Yes the command line is a bit more complicated because of the being a generic "catch all" scripte. It needs the ip adress of the led dimmer the 6 digits mac adress and the idx before the command begins.

e.g h801-leddimmer.sh 192.168.2.122 de979d 265 fun mixedcolortransistion.
or h801-leddimmer.sh 192.168.2.122 de979d 265 off

If you run the script if should state these examples as well.

Unfortunately I had to make the script even more complex due to it causing a loop when executed in domoitcz. When activated in Domoitcz the "status update" to domoticz re triggers the switch on again. this is very similar like this forum topic viewtopic.php?f=11&t=2908. The only way to stop it I could find was setting a timer for for sending another update to domoticz. not ideal but it works.

In theory you can make the script a lot more simplistic if you like to have it have one script per led dimmer. all the input checks can then be removed as long as the IP, mac address and domoticz id is hardcoded.

Below I quickly removed checks within the Script and hardcode my h801 dimmer. but as said I rather have a bit more complex catch all script with the ip address etc in the (domoticz command line.

Code: Select all

#!/bin/bash
#########
#
# Bash remote script for controlling H801 WiFi led controller
# version 0.1 Evert
#
# 0.1 Simplistic script with hardcode leddimmer details based on h801-dimmer.sh script
#`
# dependency fping and netcat (nc)
# format hex string to led dimmer for color "fbeb RRGGBB WW(1) WW(2) MM(6) MM(5) MM(4) 00 " ( for multiple add the next 3 MAC otects MM(6) MM(5) MM(4) 00
# where "fbeb" is  rgb color and "fbec" is fixed modes
# RR=Red, GG=Green, BB=Blue, WW(1)=White1, WW(2)=White2,  MM(6)=Mac octet 6, MM(5)=Mac octet 5, MM(4)=Mac octet4
# e.g fbeb00000000005c979d00ad1a0200 or fbeb00000000005c979d00
# Input script example h801-leddimmer.sh 192.168.2.121 ad1a02 264 rgbww ff20000a00


#script:///home/pi/domoticz/scripts/bash/h801-leddimmer.sh  192.168.2.120 5c979d 263 comfort

#########

#
# Init
# Domoticz server

DOMO_SERVER="192.168.2.176"
IP="192.168.2.120"
MACTOTAL="5c979d"
DOMOIDX="263"

MODUS=$1
RGBWW=$2
SPECIALMODE=$2

#
## Functions
#

errormsg ()  {
                loggerall "###### H801 WiFi controller script error message"
                loggerall "# Script options are on, off, comfort, relax, reading, energize, concentrate, fun monochromelight, and rgbww RRGGBBW1W2"
                loggerall "# When RRGGBBW1W2 is used RR is red in hex notation, GG is green, BB is Blue, W1 is white1 and W2 is white e.g rgbww 1213145000"
                loggerall "# When fun is used options are fullcolor, monochromeshade, monochromefade, monochromelight, mixedcolorshade, mixedcolorfade,"
                loggerall "# mixedcolorlight, redfade, greenfade, bluefade, monochrometransition, mixedcolortransistion, sevencolortransistion"
                loggerall "# Input script example h801-leddimmer.sh 192.168.2.121 ad1a02 264 rgbww ff20000a00"
                loggerall "#"
                loggerall "# Input recieved was : $1 $2 $3 $4 $5"
                loggerall "#"
                loggerall "######"
}

loggerall ()  {
                logger $1
                echo $1
}


checkalive () {
                loggerall  "Checking host alive $1"

                fping -c2 -t300 $IP 2>/dev/null 1>/dev/null #fping is not a standard packages and needs to be instaled

                if  [ "$?" = 0 ]
                    then
                        loggerall "Host $1 was found alive"
                    else
                        errormsg $1
                        loggerall "Host $1 was not found alive ( is fping installed)"
                        exit 1
                fi
}

onofffunction ()  {
                loggerall "Switching $1 $2"

                #Set in rgb accept mode ( twice to make sure....)
                #Set normalmode="fbec000100000079979d00" (example)
                FULLRGBWW=fbec0001000000$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #Set a color to let the power off/on work after the set mode
                FULLRGBWW=fbebff20000a00$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #The real on off command
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  if [ $2 = "off" ]; then FULLRGBWW=fbeb0000000000$MACTOTAL; echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977; fi
                  if [ $2 = "on" ];  then FULLRGBWW=fbebff20000a00$MACTOTAL; echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977; fi
                 let COUNTER=COUNTER+1
                done

                #Update domoticz
                if [ $2 = "on" ] ; then updatedomoticz $IP 1 ; fi
                if [ $2 = "off" ]; then updatedomoticz $IP 0 ; fi

}


rgbwwfunction ()  {
                loggerall "Switching $1 in rgbww $2"

                #Set in rgb accept mode
                #Set normalmode="fbec001e00000079979d00"
                FULLRGBWW=fbec0001000000$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #Set the rgb value
                FULLRGBWW=fbeb$2$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                updatedomoticz $IP 1


}

funfunction () {
                loggerall "Switching $1 in fun $2"
                #Set in in specific mode
                SPECIALRGBWW=fbec$2$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  echo -ne "$(echo $SPECIALRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                updatedomoticz $IP 1
}

updatedomoticz (){
               #
               # Check the difference in last update time stamp with current time stamp to see if there was a wrong trigger
               #
               TIME=`date -d"$(curl  --request GET "http://$DOMO_SERVER/json.htm?type=devices&rid=$DOMOIDX" | grep "LastUpdate" | awk ' {print ($3=(substr($3,2,10))),($4=(substr($4,0,9)))}')" +%s`
               CURRENT_TIME=`date +"%s"`
               DIFFERENCE=$(($CURRENT_TIME - $TIME))

               if (( "$DIFFERENCE" > 30))
                 then
                    loggerall "Updating $1 Domoticz status time differance bigger than 30 "
                     curl --request GET "http://$DOMO_SERVER/json.htm?type=command&param=udevice&idx=$DOMOIDX&nvalue=$2"&
                     sleep  2
                 else
                    loggerall "NOT updated $1 Domoticz status due to difference not smaller than 30 "
                    sleep 2
               fi
}


#######################
#
## Program
#
#######################


case "$MODUS:$SPECIALMODE" in

  "-?":*)                       errormsg                        ;;

## begin list of commands.

  "on":*)                        onofffunction $IP on            ;;
  "off":*)                       onofffunction $IP off           ;;
  "comfort":*)                   rgbwwfunction $IP ff20000a00    ;;
  "relax":*)                     rgbwwfunction $IP c8fa002000    ;;
  "reading":*)                   rgbwwfunction $IP f2f2f20000    ;;
  "energize":*)                  rgbwwfunction $IP 00d0ff0000    ;;
  "concentrate":*)               rgbwwfunction $IP 00c5db0000    ;;
  "rgbww":*)                     rgbwwfunction $IP $RGBWW        ;;
  "fun":"monochromeshade")       funfunction   $IP 0201000000    ;;
  "fun":"monochromefade")        funfunction   $IP 0301000000    ;;
  "fun":"monochromelight")       funfunction   $IP 0401000000    ;;
  "fun":"mixedcolorshade")       funfunction   $IP 0501000000    ;;
  "fun":"mixedcolorfade")        funfunction   $IP 0601000000    ;;
  "fun":"mixedcolorlight")       funfunction   $IP 0701000000    ;;
  "fun":"redfade")               funfunction   $IP 0801000000    ;;
  "fun":"greenfade")             funfunction   $IP 0901000000    ;;
  "fun":"bluefade")              funfunction   $IP 0a01000000    ;;
  "fun":"monochrometransition")  funfunction   $IP 0b01000000    ;;
  "fun":"mixedcolortransistion") funfunction   $IP 0c01000000    ;;
  "fun":"sevencolortransistion") funfunction   $IP 0d01000000    ;;


  *:*)                          errormsg
                                loggerall "Error: no valid input for mode recieved"                             ;;


esac

echo done
exit 0

orginial script with input checks and loop prevent timer.

Code: Select all

#!/bin/bash
#########
#
# Bash remote script for controlling H801 WiFi led controller
# version 0.4 Evert
#
# 0.4 added udatedomotiz funtion to prevent "flapping"/keep on swithing device
#`
# dependency fping and netcat (nc)
# format hex string to led dimmer for color "fbeb RRGGBB WW(1) WW(2) MM(6) MM(5) MM(4) 00 " ( for multiple add the next 3 MAC otects MM(6) MM(5) MM(4) 00
# where "fbeb" is  rgb color and "fbec" is fixed modes
# RR=Red, GG=Green, BB=Blue, WW(1)=White1, WW(2)=White2,  MM(6)=Mac octet 6, MM(5)=Mac octet 5, MM(4)=Mac octet4
# e.g fbeb00000000005c979d00ad1a0200 or fbeb00000000005c979d00
# Input script example h801-leddimmer.sh 192.168.2.121 ad1a02 264 rgbww ff20000a00




#########

#
# Init
# Domoticz server

DOMO_SERVER="192.168.2.176"


#
## Functions
#

errormsg ()  {
                loggerall "###### H801 WiFi controller script error message"
                loggerall "# Script options are on, off, comfort, relax, reading, energize, concentrate, fun monochromelight, and rgbww RRGGBBW1W2"
                loggerall "# When RRGGBBW1W2 is used RR is red in hex notation, GG is green, BB is Blue, W1 is white1 and W2 is white e.g rgbww 1213145000"
                loggerall "# When fun is used options are fullcolor, monochromeshade, monochromefade, monochromelight, mixedcolorshade, mixedcolorfade,"
                loggerall "# mixedcolorlight, redfade, greenfade, bluefade, monochrometransition, mixedcolortransistion, sevencolortransistion"
                loggerall "# Input script example h801-leddimmer.sh 192.168.2.121 ad1a02 264 rgbww ff20000a00"
                loggerall "#"
                loggerall "# Input recieved was : $1 $2 $3 $4 $5"
                loggerall "#"
                loggerall "######"
}

loggerall ()  {
                logger $1
                echo $1
}


checkalive () {
                loggerall  "Checking host alive $1"

                fping -c2 -t300 $IP 2>/dev/null 1>/dev/null #fping is not a standard packages and needs to be instaled

                if  [ "$?" = 0 ]
                    then
                        loggerall "Host $1 was found alive"
                    else
                        errormsg $1
                        loggerall "Host $1 was not found alive ( is fping installed)"
                        exit 1
                fi
}

onofffunction ()  {
                loggerall "Switching $1 $2"

                #Set in rgb accept mode ( twice to make sure....)
                #Set normalmode="fbec000100000079979d00" (example)
                FULLRGBWW=fbec0001000000$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #Set a color to let the power off/on work after the set mode
                FULLRGBWW=fbebff20000a00$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #The real on off command
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  if [ $2 = "off" ]; then FULLRGBWW=fbeb0000000000$MACTOTAL; echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977; fi
                  if [ $2 = "on" ];  then FULLRGBWW=fbebff20000a00$MACTOTAL; echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977; fi
                 let COUNTER=COUNTER+1
                done

                #Update domoticz
                if [ $2 = "on" ] ; then updatedomoticz $IP 1 ; fi
                if [ $2 = "off" ]; then updatedomoticz $IP 0 ; fi

}


rgbwwfunction ()  {
                loggerall "Switching $1 in rgbww $2"

                #Set in rgb accept mode
                #Set normalmode="fbec001e00000079979d00"
                FULLRGBWW=fbec0001000000$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                   echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                #Set the rgb value
                FULLRGBWW=fbeb$2$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  echo -ne "$(echo $FULLRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                updatedomoticz $IP 1


}

funfunction () {
                loggerall "Switching $1 in fun $2"
                #Set in in specific mode
                SPECIALRGBWW=fbec$2$MACTOTAL
                COUNTER=0
                while [  $COUNTER -lt 2 ]; do
                  echo -ne "$(echo $SPECIALRGBWW | sed -e 's/../\\x&/g')" | nc -u -w1 $1 30977
                 let COUNTER=COUNTER+1
                done

                updatedomoticz $IP 1
}

updatedomoticz (){
               #
               # Check the difference in last update time stamp with current time stamp to see if there was a wrong trigger
               #
               TIME=`date -d"$(curl  --request GET "http://$DOMO_SERVER/json.htm?type=devices&rid=$DOMOIDX" | grep "LastUpdate" | awk ' {print ($3=(substr($3,2,10))),($4=(substr($4,0,9)))}')" +%s`
               CURRENT_TIME=`date +"%s"`
               DIFFERENCE=$(($CURRENT_TIME - $TIME))

               if (( "$DIFFERENCE" > 30))
                 then
                    loggerall "Updating $1 Domoticz status time differance bigger than 30 "
                     curl --request GET "http://$DOMO_SERVER/json.htm?type=command&param=udevice&idx=$DOMOIDX&nvalue=$2"&
                     sleep  2
                 else
                    loggerall "NOT updated $1 Domoticz status due to difference not smaller than 30 "
                    sleep 2
               fi
}

#
## Check and process input
#

#Check if a minimum one input supplied
if [[ $# -lt 4 ]] #Check to see if at least one parameter is supplied
    then
        errormsg $1 $2 $3 $4 $5
        loggerall "Error: A minimum of four inputs please"
        exit 1
fi


#Check that first input is valid IPv4 IP address and alive
#Declare IP variable
if [[  "$(echo $1 | grep '[0-9]\{1,3\}[.][0-9]\{1,3\}[.][0-9]\{1,3\}[.][0-9]\{1,3\}')" ]]
   then
      loggerall "Ip address used '$1' "
      IP=$1
      checkalive $IP
   else
      errormsg $1 $2 $3 $4 $5
      loggerall "Ip address not valid '$1'"
      exit 1
fi


#Declare second input as led dimmer mac address id
if [[ ! $2 =~ ^-?[0-9a-fA-F]+$ ]] #Check to see if only numbers and characters a till f (hex) are supplied
    then
        errormsg $1 $2 $3 $4 $5
        loggerall "Error: Mac address address in format Mac6 MAC5 MAC4 in hex"
        exit 1
    else
        MACTOTAL=$2
        declare -l MACTOTAL
        MACTOTAL=$MACTOTAL"00" #adding the trailing 00 as well
fi


#Declare the third input as DOMOIDX
if [[ ! $3 =~ ^-?[0-9]+$ ]]
   then
      errormsg $1 $2 $3 $4 $5
      loggerall "Error: Domoticz idx must be a number"
      exit 1
   else
      DOMOIDX=$3
fi

#Declare  fourth input as variable MODUS all lowercase
if [[ ! $4 =~ ^-?[a-zA-Z]+$ ]] #Check to see if only characters are supplied
    then
        errormsg $1 $2 $3 $4 $5
        loggerall "Error: Mode input should only be characters"
        exit 1
    else
        MODUS=$4
        declare -l MODUS # Define lower case
        MODUS=$MODUS
fi

#Make sure that if rgbww or fun is selected as modus a 5th input is there
if [[ $4 = "rgbww" && $5 = "" ]] || [[ $4 = "fun" && $5 = "" ]]
   then
      errormsg $1 $2 $3 $4 $5
      loggerall "Error: If rgbww or fun is the input a second input is required"
      exit 1
fi


#Declare fith  input as RGBWW if fourth input is rgbww
if [[  $MODUS = "rgbww" && ! $5 = "" ]]
   then
       if [[ ! $5 =~ ^-?[0-9a-fA-F]+$ ]] #Check to see if only numbers and characters a till f are supplied
          then
              errormsg $1 $2 $3 $4 $5
              loggerall "Error: rgb w1 w2 value can only be hex numbers"
              exit 1
          else
              if [[ ! ${#5} = 10 ]] # Check that input string is 10 long
                 then
                     errormsg $1 $2 $3 $4 $5
                     loggerall "Error: rgb w1 w2 must be 10 hex numbers"
                     exit 1
                 else
                     RGBWW=$5
                     declare -l RGBWW
                     RGBWW=$RGBWW
              fi
       fi
fi

#Declare fith input as SPECIALMODE if fourth input is fun
if [[  $MODUS = "fun" && ! $5 = "" ]]
   then
       if [[ ! $5 =~ ^-?[a-zA-Z]+$ ]] #Check to see if characters (a till z) are supplied
           then
               errormsg $1 $2 $3 $4 $5
               loggerall "Error: With the argument fun there must be a specialmode defined"
               exit 1
           else
               SPECIALMODE=$5
               declare -l SPECIALMODE
               SPECIALMODE=$SPECIALMODE
       fi
fi

#######################
#
## Program
#
#######################


case "$MODUS:$SPECIALMODE" in

  "-?":*)                       errormsg                        ;;

## begin list of commands.

  "on":*)                        onofffunction $IP on            ;;
  "off":*)                       onofffunction $IP off           ;;
  "comfort":*)                   rgbwwfunction $IP ff20000a00    ;;
  "relax":*)                     rgbwwfunction $IP c8fa002000    ;;
  "reading":*)                   rgbwwfunction $IP f2f2f20000    ;;
  "energize":*)                  rgbwwfunction $IP 00d0ff0000    ;;
  "concentrate":*)               rgbwwfunction $IP 00c5db0000    ;;
  "rgbww":*)                     rgbwwfunction $IP $RGBWW        ;;
  "fun":"monochromeshade")       funfunction   $IP 0201000000    ;;
  "fun":"monochromefade")        funfunction   $IP 0301000000    ;;
  "fun":"monochromelight")       funfunction   $IP 0401000000    ;;
  "fun":"mixedcolorshade")       funfunction   $IP 0501000000    ;;
  "fun":"mixedcolorfade")        funfunction   $IP 0601000000    ;;
  "fun":"mixedcolorlight")       funfunction   $IP 0701000000    ;;
  "fun":"redfade")               funfunction   $IP 0801000000    ;;
  "fun":"greenfade")             funfunction   $IP 0901000000    ;;
  "fun":"bluefade")              funfunction   $IP 0a01000000    ;;
  "fun":"monochrometransition")  funfunction   $IP 0b01000000    ;;
  "fun":"mixedcolortransistion") funfunction   $IP 0c01000000    ;;
  "fun":"sevencolortransistion") funfunction   $IP 0d01000000    ;;


  *:*)                          errormsg
                                loggerall "Error: no valid input for mode recieved"                             ;;


esac

echo done
exit 0
User avatar
ledfreak3d
Posts: 98
Joined: Sunday 01 November 2015 15:30
Target OS: Linux
Domoticz version: 3.8025
Location: Hoorn
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ledfreak3d »

so still no good way to support this module ?
might just have to flash it with quinled and just add 2 extra channels
Unleashe the magic smoke ;)
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by BigDog »

interesting i wil watch this post :) and i find it a interesting module :)
been experimetning with the esp :)
1X Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ThinkPad »

ledfreak3d wrote:so still no good way to support this module ?
might just have to flash it with quinled and just add 2 extra channels
Something that i thought of, but i don't want to lose the default firmware. And i am not sure how to make a backup of it....
I am not active on this forum anymore.
User avatar
ledfreak3d
Posts: 98
Joined: Sunday 01 November 2015 15:30
Target OS: Linux
Domoticz version: 3.8025
Location: Hoorn
Contact:

Re: [ESP8266] Commercial H801 WiFi RGB-dimmer topic

Post by ledfreak3d »

I dont mind flashing the fw
Ive bought them for that purpose lol

Quinled works wel no reason why it could not do 5 channels
Unleashe the magic smoke ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests