Created
September 30, 2017 09:20
-
-
Save waldheinz/63f32ef1662cd4fbcdf72a883b733763 to your computer and use it in GitHub Desktop.
Prometheus Exporter for Homematic CCU
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
#!/bin/tclsh | |
load tclrega.so | |
source [file join $env(DOCUMENT_ROOT) once.tcl] | |
source [file join $env(DOCUMENT_ROOT) cgi.tcl] | |
cgi_eval { | |
cgi_input | |
cgi_content_type "text/plain; charset=iso-8859-1; version=0.0.4" | |
set list "" | |
catch { import list } | |
array set res [rega_script { | |
string s_device; | |
object o_device; | |
string s_channel; | |
object o_channel; | |
string s_dp; | |
object o_dp; | |
foreach(s_device, dom.GetObject(ID_DEVICES).EnumUsedIDs()) { | |
var o_device = dom.GetObject(s_device); | |
if ((o_device.Address() != "BidCoS-Wir") && (o_device.Address() != "BidCoS-RF")) { | |
! WriteLine(o_device.Address() # " " # o_device.HssType() # " (" # o_device.Name() # ")"); | |
foreach(s_channel, o_device.Channels().EnumUsedIDs()) { | |
o_channel = dom.GetObject(s_channel); | |
foreach (s_dp, o_channel.DPs().EnumUsedIDs()) { | |
o_dp = dom.GetObject(s_dp); | |
integer val_tp = o_dp.ValueType(); | |
string val_str; | |
if (val_tp == 2) { | |
if (o_dp.Value()) { | |
val_str = "1"; | |
} else { | |
val_str = "0"; | |
} | |
} else { | |
val_str = o_dp.Value().ToString(); | |
} | |
if (val_str.Length() > 0) { | |
WriteLine("homematic_dp_value{" | |
# "channel_id=\"" # s_channel | |
# "\", dev_address=\"" # o_device.Address() | |
# "\", dev_hss_type=\"" # o_device.HssType() | |
# "\", dev_hss_type_name=\"" # o_device.TypeName() | |
# "\", dev_interface=\"" # o_device.Interface() | |
# "\", dev_name=\"" # o_device.Name() | |
# "\", dp_id=\"" # s_dp | |
# "\", dp_type=\"" # val_tp | |
# "\", dp_hss_type=\"" # o_dp.HssType() | |
# "\", dp_hss_type_name=\"" # o_dp.TypeName() | |
# "\"} " # val_str ) | |
} | |
} | |
} | |
} | |
} | |
}] | |
set response [string map {\r\n \n} $res(STDOUT)] | |
puts $response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have an issue when "val_tp == 20" (RGBW) then the val_str is rgb(255,255,255,255) and prometheus fails during scraping and no value will be stored.
i just added this to line 45 and 46:
} elseif (val_tp == 20) {
val_str = "0";