mtx-context-domotica.tex / last modification: 2020-01-30 14:16
%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 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
% example: context --extra=domotica --hue pragma-youless-gas.lua --year=2018 --month=8
% example: context --extra=domotica --hue pragma-youless-electricity.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 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 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


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

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

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




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







    \starttitle[title=Zwave devices]



        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")


        elseif noffiles > 0 then

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

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


            context("no files given")









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

    local action    = (arguments.tasks                     and "task")
                   or (                  and "graphics")
                   or (string.find(filename,"tasks")       and "tasks")
                   or (string.find(filename,"electricity") and "graphics")
                   or (string.find(filename,"pulse")       and "graphics")
                   or (string.find(filename,"gas")         and "graphics")

    if not filename or filename == "" then"youless","provide filename")
        context("no files given")
    elseif action == "tasks" then
        context.starttitle { title = "Hue: " .. file.nameonly(filename) }
        filename = file.addsuffix(filename,"lua")
        if lfs.isfile(filename) then
            context("unknown file %a",filename)
    elseif action == "graphics" then { year = year, month = month, filename = filename }
    else"youless","provide --status or --graphics")
        context("no action given")