mtx-context-domotica.tex /size: 7106 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=mtx-context-domotica,
3%D        version=2016.10.20,
4%D          title=\CONTEXT\ Extra Trickry,
5%D       subtitle=Domotica Goodies,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14% begin help
15%
16% usage: context --extra=domotica [options] list-of-files
17%
18% --topspace=dimension  : distance above first line
19% --backspace=dimension : distance before left margin
20% --bodyfont=list       : additional bodyfont settings
21% --paperformat=spec    : paper*print or paperxprint
22% --compact             : small margins, 8pt font
23% --verycompact         : small margins, 7pt font
24%
25% --openzwave           : process openzwave xml files
26% --hue                 : process hue task file
27%
28% --pattern=spec        : files to process
29%
30% example: context --extra=domotica --openzwave ./config/fibaro/fgms.xml ./open-zwave-master/config/aeotec/zw100.xml
31% example: context --extra=domotica --openzwave --pattern="./open-zwave-master/config/**.xml"
32% example: context --extra=domotica --hue hue-pragma-tasks.lua
33% example: context --extra=domotica --hue pragma-youless-gas.lua --year=2018 --month=8
34% example: context --extra=domotica --hue pragma-youless-electricity.lua
35%
36% end help
37
38%D In case one wonders what domotica has to do with ConTeXt, here is the short
39%D story. One day I'll wrap up a long one.
40%D
41%D After years of keeping an eye on developments and techniques and being somewhat
42%D disappointed by experiments, I decided to settle on a local approach for simple
43%D domotica (criteria are: stability, full open source, decent scripting, future
44%D safe). Eventually I decides to buy a few (overpriced) hue zigbee hubs: one
45%D private and one for the office, so that I could create different lightning
46%D setups, automatically control light to be turned on and off, etc. Unfortunately
47%D those hubs are rather limited in functionality and performance, which is
48%D surprising for an otherwise mature product. So (we're speaking mid 2015) I wrote
49%D a couple of scripts in \LUA\ that would do the real magic, and only use the hub
50%D for controlling the individual lights, buttons and sensors. That way I could
51%D create complex arrangements (think of setups for working, reading, talking,
52%D either of not in parts or rooms) driven by the available buttons and motion
53%D sensors. I really needed multiple sensors and buttons per room, something (again
54%D surprisingly) not supported by the hub at that time. It seems that more than a
55%D year later functionality that I needed and wrote gets added stepwise to the hub:
56%D multiple sensors, multiple use of buttons, etc. Compared to free \TEX\
57%D developments such commercial products evolve slow.
58%D
59%D In addition to these hubs I bought some zwave devices for controlling heating and
60%D a few rf radio things for sunshades. For zwave I uses the same approach: buy a
61%D decent hub (the nice popp hub) and control it via \LUA. In fact, I can now use
62%D one set of scripts to control a mix of technologies. However, when programming
63%D the lot, one needs to have an overview of devices and that is where this module
64%D comes into view. In fact, \LUATEX\ was already in view as I wrote the scripts in
65%D \LUA, using the \CONTEXT\ helper libraries. And the lots runs on a small low
66%D power (<10W) fitlet using stock \LUATEX\ as \LUA\ engine.
67
68% --pattern="e:/domotica/open-zwave/open-zwave-master/config/**.xml"
69
70\input mtx-context-common.tex
71
72\usemodule[domotica-settings]
73
74\doifdocumentargument {compact} {
75    \setdocumentargument{topspace} {5mm}
76    \setdocumentargument{backspace}{5mm}
77    \setdocumentargument{bodyfont} {8pt}
78}
79
80\doifdocumentargument {verycompact} {
81    \setdocumentargument{topspace} {5mm}
82    \setdocumentargument{backspace}{5mm}
83    \setdocumentargument{bodyfont} {7pt}
84}
85
86\setupbodyfont
87  [dejavu,11pt,\getdocumentargument{bodyfont}] % dejavu is more complete
88
89\setuplayout
90  [header=0cm,
91   footer=1.5cm,
92   topspace=\getdocumentargumentdefault{topspace}{1.5cm},
93   backspace=\getdocumentargumentdefault{backspace}{1.5cm},
94   width=middle,
95   height=middle]
96
97\setuppapersize
98  [\getdocumentargument{paperformat_paper}]
99  [\getdocumentargument{paperformat_print}]
100
101\setuphead
102  [section]
103  [style=bold]
104
105\doifdocumentargument {openzwave} {\enablemode[openzwave]}
106\doifdocumentargument {hue}       {\enablemode[hue]}
107
108\startmode[openzwave]
109
110    \starttext
111
112    \setuplist
113      [chapter]
114      [style=bold,
115       width=4em]
116
117    \setuplist
118      [section]
119      [width=4em]
120
121    \setupheadertexts
122
123    \setupheadertexts
124      [chapter][pagenumber]
125
126    \starttitle[title=Zwave devices]
127
128        \placelist[chapter,section]
129
130    \stoptitle
131
132    \startluacode
133        local arguments = document.arguments
134        local files     = document.files
135        local pattern   = arguments.pattern
136        local noffiles  = #files
137
138        if type(pattern) == "string" then
139
140            local pattern = file.addsuffix(pattern,"xml")
141
142            moduledata.zwave.show_settings(pattern)
143
144        elseif noffiles > 0 then
145
146         -- if arguments.sort then
147         --     table.sort(files)
148         -- end
149
150            for i=1,#files do
151                local filename = file.addsuffix(files[i],"xml")
152                moduledata.zwave.show_settings(filename)
153            end
154
155        else
156
157            context("no files given")
158
159        end
160    \stopluacode
161
162    \stoptext
163
164\stopmode
165
166
167\startmode[hue]
168
169    \usemodule[youless]
170
171    \starttext
172
173    \setupheadertexts
174
175    \startluacode
176
177    local arguments = document.arguments
178    local files     = document.files
179    local filename  = files[1]
180    local pattern   = arguments.pattern
181    local year      = arguments.year
182    local month     = arguments.month
183
184    local action    = (arguments.tasks                     and "task")
185                   or (arguments.graphics                  and "graphics")
186                   or (string.find(filename,"tasks")       and "tasks")
187                   or (string.find(filename,"electricity") and "graphics")
188                   or (string.find(filename,"pulse")       and "graphics")
189                   or (string.find(filename,"gas")         and "graphics")
190
191    if not filename or filename == "" then
192        logs.report("youless","provide filename")
193        context("no files given")
194    elseif action == "tasks" then
195        context.starttitle { title = "Hue: " .. file.nameonly(filename) }
196        filename = file.addsuffix(filename,"lua")
197        if lfs.isfile(filename) then
198            moduledata.hue.show_state(filename)
199        else
200            context("unknown file %a",filename)
201        end
202        context.stoptitle()
203    elseif action == "graphics" then
204        moduledata.youless.graphics { year = year, month = month, filename = filename }
205    else
206        logs.report("youless","provide --status or --graphics")
207        context("no action given")
208    end
209
210    \stopluacode
211
212    \stoptext
213
214\stopmode
215
216
217