diff --git a/Script-Cookbook.md b/Script-Cookbook.md index 21d283d8..c227e307 100644 --- a/Script-Cookbook.md +++ b/Script-Cookbook.md @@ -10,6 +10,7 @@ - [Switching and Dimming By Recognizing Mains Power Frequency](#Switching-and-Dimming-By-Recognizing-Mains-Power-Frequency) - [Web UI](#Web-UI) - [Hue Emulation](#hue-emulation) +- [Alexa Controlled MCP230xx I2C GPIO Expander](#alexa-controlled-mcp230xx-i2c-gpio-expander) [Back To Top](#top) @@ -1159,3 +1160,70 @@ livingroom,E,on=pwr1,hue=hue1,sat=sat1,bri=bri1 ------------------------------------------------------------------------------ +#### Alexa Controlled MCP230xx I2C GPIO Expander +Uses Tasmota's Hue Emulation capabilities for Alexa interface + +>; define vars +**>D** +p:p1=0 +p:p2=0 +p:p3=0 +p:p4=0 + +>; init ports +**>B** +->sensor29 0,5,0 +->sensor29 1,5,0 +->sensor29 2,5,0 +->sensor29 3,5,0 +->sensor29 0,%0p1% +->sensor29 1,%0p2% +->sensor29 2,%0p3% +->sensor29 3,%0p4% + +>; define Alexa virtual devices +**>H** +port1,S,on=p1 +port2,S,on=p2 +port3,S,on=p3 +port4,S,on=p4 + +>; handle events +**>E** +print EVENT +> +>if upd[p1]>0 +then +->sensor29 0,%0p1% +endif +if upd[p2]>0 +then +->sensor29 1,%0p2% +endif +if upd[p3]>0 +then +->sensor29 2,%0p3% +endif +if upd[p4]>0 +then +->sensor29 3,%0p4% +endif +> +>=#pub + +>; publish routine +#pub +=>publish stat/%topic%/RESULT {"MCP23XX":{"p1":%0p1%,"p2":%0p2%,"p3":%0p3%,"p4":%0p4%}} +svars + +>; web interface +**>W** +bu(p1 "p1 on" "p1 off")bu(p2 "p2 on" "p2 off")bu(p3 "p3 on" "p3 off")bu(p4 "p4 on" "p4 off") + +>;json output +**>J** +;,"MCP23XX":{"p1":%0p1%,"p2":%0p2%,"p3":%0p3%,"p4":%0p4%} + +[Back To Top](#top) + +------------------------------------------------------------------------------