summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/mtx-context-domotica.tex
blob: 83562ee30cf9e2c4a1d93f21d308c082a97fd13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
%D \module
%D   [       file=mtx-context-domotica,
%D        version=2016.10.20,
%D          title=\CONTEXT\ Extra Trickry,
%D       subtitle=Domotica Goodies,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% begin help
%
% usage: context --extra=domotica [options] list-of-files
%
% --topspace=dimension  : distance above first line
% --backspace=dimension : distance before left margin
% --bodyfont=list       : additional bodyfont settings
% --paperformat=spec    : paper*print or paperxprint
% --compact             : small margins, 8pt font
% --verycompact         : small margins, 7pt font
%
% --openzwave           : process openzwave xml files
% --hue                 : process hue task file
%
% --pattern=spec        : files to process
%
% example: context --extra=domotica --openzwave ./config/fibaro/fgms.xml ./open-zwave-master/config/aeotec/zw100.xml
% example: context --extra=domotica --openzwave --pattern="./open-zwave-master/config/**.xml"
% example: context --extra=domotica --hue       hue-pragma-tasks.lua
%
% end help

%D In case one wonders what domotica has to do with ConTeXt, here is the short
%D story. One day I'll wrap up a long one.
%D
%D After years of keeping an eye on developments and techniques and being somewhat
%D disappointed by experiments, I decided to settle on a local approach for simple
%D domotica (criteria are: stability, full open source, decent scripting, future
%D safe). Eventually I decides to buy a few (overpriced) hue zigbee hubs: one
%D private and one for the office, so that I could create different lightning
%D setups, automatically control light to be turned on and off, etc. Unfortunately
%D those hubs are rather limited in functionality and performance, which is
%D surprising for an otherwise mature product. So (we're speaking mid 2015) I wrote
%D a couple of scripts in \LUA\ that would do the real magic, and only use the hub
%D for controlling the individual lights, buttons and sensors. That way I could
%D create complex arrangements (think of setups for working, reading, talking,
%D either of not in parts or rooms) driven by the available buttons and motion
%D sensors. I really needed multiple sensors and buttons per room, something (again
%D surprisingly) not supported by the hub at that time. It seems that more than a
%D year later functionality that I needed and wrote gets added stepwise to the hub:
%D multiple sensors, multiple use of buttons, etc. Compared to free \TEX\
%D developments such commercial products evolve slow.
%D
%D In addition to these hubs I bought some zwave devices for controlling heating and
%D a few rf radio things for sunshades. For zwave I uses the same approach: buy a
%D decent hub (the nice popp hub) and control it via \LUA. In fact, I can now use
%D one set of scripts to control a mix of technologies. However, when programming
%D the lot, one needs to have an overview of devices and that is where this module
%D comes into view. In fact, \LUATEX\ was already in view as I wrote the scripts in
%D \LUA, using the \CONTEXT\ helper libraries. And the lots runs on a small low
%D power (<10W) fitlet using stock \LUATEX\ as \LUA\ engine.

% --pattern="e:/domotica/open-zwave/open-zwave-master/config/**.xml"

\input mtx-context-common.tex

\usemodule[domotica-settings]

\doifdocumentargument {compact} {
    \setdocumentargument{topspace} {5mm}
    \setdocumentargument{backspace}{5mm}
    \setdocumentargument{bodyfont} {8pt}
}

\doifdocumentargument {verycompact} {
    \setdocumentargument{topspace} {5mm}
    \setdocumentargument{backspace}{5mm}
    \setdocumentargument{bodyfont} {7pt}
}

\setupbodyfont
  [dejavu,11pt,\getdocumentargument{bodyfont}] % dejavu is more complete

\setuplayout
  [header=0cm,
   footer=1.5cm,
   topspace=\getdocumentargumentdefault{topspace}{1.5cm},
   backspace=\getdocumentargumentdefault{backspace}{1.5cm},
   width=middle,
   height=middle]

\setuppapersize
  [\getdocumentargument{paperformat_paper}]
  [\getdocumentargument{paperformat_print}]

\setuphead
  [section]
  [style=bold]

\doifdocumentargument {openzwave} {\enablemode[openzwave]}
\doifdocumentargument {hue}       {\enablemode[hue]}

\startmode[openzwave]

    \starttext

    \setuplist
      [chapter]
      [style=bold,
       width=4em]

    \setuplist
      [section]
      [width=4em]

    \setupheadertexts

    \setupheadertexts
      [chapter][pagenumber]

    \starttitle[title=Zwave devices]

        \placelist[chapter,section]

    \stoptitle

    \startluacode
        local arguments = document.arguments
        local files     = document.files
        local pattern   = arguments.pattern
        local noffiles  = #files

        if type(pattern) == "string" then

            local pattern = file.addsuffix(pattern,"xml")

            moduledata.zwave.show_settings(pattern)

        elseif noffiles > 0 then

         -- if arguments.sort then
         --     table.sort(files)
         -- end

            for i=1,#files do
                local filename = file.addsuffix(files[i],"xml")
                moduledata.zwave.show_settings(filename)
            end

        else

            context("no files given")

        end
    \stopluacode

    \stoptext

\stopmode

\startmode[hue]

    \starttext

    \setupheadertexts

    \startluacode

    local arguments = document.arguments
    local files     = document.files
    local pattern   = arguments.pattern
    local filename  = files[1]

    if filename then
        context.starttitle { title = "Hue: " .. file.nameonly(filename) }
        filename = file.addsuffix(filename,"lua")
        if lfs.isfile(filename) then
            moduledata.hue.show_state(filename)
        else
            context("unknown file %a",filename)
        end
        context.stoptitle()
    else
        context("no files given")
        context.stoptitle()
    end

    \stopluacode

    \stoptext

\stopmode