-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file does nothing it just contains some | ||
# examples to suit your needs depending on project | ||
# It will be copied into filesystem to be editable | ||
# ===================================================== | ||
|
||
# Set auto timezone | ||
#tasmota.cmd("Backlog0 Timezone 99; TimeStd 0,0,10,1,3,60; TimeDst 0,0,3,1,2,120") | ||
|
||
# Set Teleinfo in legacy (historique) mode at 1200 baud. | ||
#tasmota.cmd("EnergyConfig Historique") | ||
|
||
# Set Teleinfo in Standar mode at 9600 baud. | ||
#tasmota.cmd("EnergyConfig Standard") | ||
|
||
# Enable sending of all frames in raw mode | ||
#tasmota.cmd("EnergyConfig Full") | ||
|
||
# Send only each 1 on 10 frames received | ||
#tasmota.cmd("EnergyConfig Skip 9") | ||
|
||
# Disable Boot Loop Detection | ||
#tasmota.cmd("SetOption65 1") | ||
|
||
# Avoid conflict between native WS2812 and Berry control | ||
# disables native WS2812 (default Scheme is 0) | ||
#tasmota.cmd("Scheme 14") | ||
|
||
# load Winky teleinfo driver | ||
load("teleinfo.be") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
# Winky Teleinfo Driver, this is just a sample file that read both | ||
# voltage (USB and Super Capacitor), display on Web UI | ||
|
||
class TELEINFO: Driver | ||
var vusb | ||
var vcap | ||
var strip | ||
var bri | ||
var is_usb | ||
var tick_500ms | ||
|
||
def init() | ||
# First we need to get Analog voltage | ||
self.tick_500ms = false | ||
self.every_500ms() | ||
|
||
# Get LED Brightness from UI | ||
var led = light.get() | ||
self.bri = led["bri"] | ||
|
||
# Instantiate our 2 WS2812 Leds | ||
self.strip = Leds(2, 2, gpio.pin(gpio.WS2812, 1)) | ||
|
||
# Check Super Capacitor Voltage | ||
if self.vcap < 4.5 | ||
# Not enough we should go to deepsleep from here | ||
self.strip.set_pixel_color(0, 0xFF0000, self.bri) | ||
self.sleep() | ||
else | ||
self.strip.set_pixel_color(0, 0x00FF00, self.bri) | ||
end | ||
self.strip.show() | ||
|
||
# create rules to trigger | ||
tasmota.add_rule("System#Init", /value -> self.set_led(0xFFFF00)) | ||
tasmota.add_rule("Wifi#Connected", /value -> self.set_led(0x00FFFF)) | ||
tasmota.add_rule("Mqtt#Connected", /value -> self.set_led(0x00FF00)) | ||
tasmota.add_rule("Tele#Energy#Power", /value -> self.done(value) ) | ||
|
||
end | ||
|
||
def analog2voltage(v) | ||
v = int(v) | ||
# Voltage is divided by 2 by a resistor R/R divider | ||
return 3.3 * 2.0 * v / 4095 | ||
end | ||
|
||
def set_deepsleep(s) | ||
#import json | ||
#var sensors=json.load(tasmota.read_sensors()) | ||
#self.on_a1(sensors['ANALOG']['A1'] ) | ||
#self.on_a2(sensors['ANALOG']['A2'] ) | ||
var cmd = "deepsleeptime " + str(s) | ||
print ("set_deepsleep() ", cmd) | ||
tasmota.cmd(cmd) | ||
end | ||
|
||
def sleep() | ||
self.strip.set_pixel_color(1, 0x000000, self.bri) | ||
self.strip.set_pixel_color(0, 0x000000, self.bri) | ||
self.strip.show() | ||
print ("sleep()") | ||
if self.is_usb == false | ||
# DEBUG | ||
print("All Done, going to sleep") | ||
if gpio.digital_read(23) != 0 | ||
# Sleep for 15s | ||
self.set_deepsleep(15) | ||
else | ||
print("Button prevented sleep") | ||
end | ||
else | ||
print("USB Connected no sleep") | ||
end | ||
end | ||
|
||
def done(value) | ||
print("Done") | ||
self.strip.set_pixel_color(1, 0x000000, self.bri) | ||
self.strip.set_pixel_color(0, 0xFF00FF, self.bri) | ||
self.strip.show() | ||
tasmota.set_timer(250, /value -> self.sleep()) | ||
end | ||
|
||
def set_led(color) | ||
# DEBUG print("Color:", color, "BRI:", self.bri) | ||
self.strip.set_pixel_color(1, color, self.bri) | ||
self.strip.show() | ||
end | ||
|
||
def every_500ms() | ||
import json | ||
import string | ||
# get Analog voltage | ||
var sensors=json.load(tasmota.read_sensors()) | ||
self.vcap = self.analog2voltage(sensors['ANALOG']['A2']) | ||
self.vusb = self.analog2voltage(sensors['ANALOG']['A1']) | ||
if self.vusb > 4.5 | ||
self.is_usb = true | ||
else | ||
self.is_usb = false | ||
end | ||
# DEBUG | ||
print(string.format("SuperCap:%.2fV USB:%.2fV USB:%d", self.vcap, self.vusb, self.is_usb)) | ||
end | ||
|
||
def every_250ms() | ||
if self.tick_500ms == true | ||
self.tick_500ms = false | ||
self.every_500ms() | ||
else | ||
self.tick_500ms = true | ||
end | ||
end | ||
|
||
def every_second() | ||
# DEBUG print("sensors:",tasmota.read_sensors()) | ||
end | ||
|
||
# display sensor value in the web UI | ||
def web_sensor() | ||
import string | ||
var msg = string.format( | ||
"{s}USB{m}%.1f V{e}" | ||
"{s}Super Capacitor{m}%.1f V{e}", | ||
self.vusb, self.vcap ) | ||
|
||
tasmota.web_send_decimal(msg) | ||
end | ||
|
||
|
||
#- add sensor value to teleperiod -# | ||
# Looks like this one prevents "Tele#Sensor#......" | ||
# to be triggered so leave it as comment for now | ||
def json_append() | ||
if !self.vusb return nil end | ||
if !self.vcap return nil end | ||
import string | ||
var msg = string.format(',"vsub":%i, "vcap":%i }', int(self.vusb*1000), int(self.vcap*1000)) | ||
# print(msg) | ||
# tasmota.response_append(msg) | ||
end | ||
|
||
end | ||
|
||
teleinfo = TELEINFO() | ||
tasmota.add_driver(teleinfo) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copy teleinfo driver to file system to be end user editable | ||
|
||
# simple function to copy from autoconfig archive to filesystem | ||
# return true if ok | ||
def cp(from, to) | ||
import path | ||
if to == nil to = from end # to is optional | ||
tasmota.log("OTA: copying "+tasmota.wd + to, 2) | ||
if !path.exists(to) | ||
try | ||
# tasmota.log("f_in="+tasmota.wd + from) | ||
var f_in = open(tasmota.wd + from) | ||
var f_content = f_in.readbytes() | ||
f_in.close() | ||
var f_out = open(to, "w") | ||
f_out.write(f_content) | ||
f_out.close() | ||
except .. as e,m | ||
tasmota.log("OTA: Couldn't copy "+to+" "+e+" "+m,2) | ||
return false | ||
end | ||
return true | ||
end | ||
return true | ||
end | ||
|
||
import path | ||
|
||
# copy some samples files from autoconf | ||
# to filesystem for end user speed up learn | ||
cp("_autoexec.be", "autoexec.be") | ||
cp("_teleinfo.be", "teleinfo.be") | ||
|
||
# Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Br load("Winky.autoconf#cp2fs.be") | ||
Template {"NAME":"Winky","GPIO":[1,4704,1376,4705,5632,4706,640,608,1,32,1,0,0,0,0,0,0,0,1,1,1,1,1,4096,0,0,0,0,0,0,0],"FLAG":0,"BASE":1} | ||
Module 0 | ||
|
||
; All these parameters are saved onto flash device | ||
; so once configured, you can change them afterward | ||
; in the file autoexec.be copied onto the filesystem | ||
; ===================================================== | ||
|
||
; Disable Boot Loop Detection | ||
SetOption65 1 | ||
|
||
; Set Telemetry to 11s (to remove 10s deepsleep) | ||
TelePeriod 11 | ||
|
||
; # Set auto timezone | ||
Backlog0 Timezone 99; TimeStd 0,0,10,1,3,60; TimeDst 0,0,3,1,2,120 | ||
|
||
; # Set Teleinfo in legacy (historique) mode at 1200 baud. | ||
EnergyConfig Historique | ||
|
||
; # Enable sending of all frames in raw mode | ||
EnergyConfig Full | ||
|
||
; # Send only each 1 on 10 frames received | ||
EnergyConfig Skip 9 |