Dashticz V2 - Custom Applications

From Domoticz
Jump to: navigation, search
_ _

Module - Moonphases

Moonphase.png

First create a lua script (example: script_time_moon.lua) with the following code

-- Variables to customize ------------------------------------------------
local moonpicture = "MoonPicture"           -- name of the uservar to write the name of the moonphase picture to
local checkvar = "MoonphaseCheck"           -- name of the uservar to check if update is allowed
local checktime = 3600                      -- check allowed every x seconds 3600 = 60 min. Check the wundergroud API limitation before changing this
local city = "<your town>"                  -- Your city for Wunderground API
local countryCode = "<YOUR COUNTRY CODE>"   -- Your country code for Wunderground API
local idxmoonpercentage ='125'              -- Your virtual moon percentage illuminated Device ID
local idxmoonage ='131'                     -- Your virtual moon age Device ID
local idxmoonphase ='132'                   -- Your virtual moon phase Device ID
local idxmoonrise='124'                     -- Your virtual moon rise variable ID
local idxmoonset='127'                      -- Your virtual moon set variable ID
local wuAPIkey = "<your key>"               -- Your Weather Underground API Key
local DOMO_IP = "<your domo ip>"            -- Domoticz ip address
local DOMO_PORT = "<your domo port>"        -- Domoticz port
local tempfilename = '/var/tmp/phase.tmp'   -- can be anywhere writeable (chmod 744)
local debug=false                           -- false, true for domoticz log
-------------------------------------------------------------------------

function file_exists(path)
    -- function to check if a file exists
    local file = io.open(path, "rb")
    if file then file:close() end
    return file ~= nil
end
 
function timedifference(s)
    -- function to determine the difference in seconds between the current time and a given one
    year = string.sub(s, 1, 4)
    month = string.sub(s, 6, 7)
    day = string.sub(s, 9, 10)
    hour = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)
    t1 = os.time()
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    difference = os.difftime (t1, t2)
    return difference
end
 
function may_update(device, timeelapsed)
    -- function to check whether an update is allowed
    return uservariables_lastupdate[device] == nil or timedifference(uservariables_lastupdate[device]) >= timeelapsed
end
 
commandArray = {}
    time = os.date("*t")
    url='http://api.wunderground.com/api/'..wuAPIkey..'/astronomy/q/'..countryCode..'/'..city..'.json'
    if (may_update(checkvar,checktime)==true) or (file_exists(tempfilename)==false) then
		
	-- read API Wunderground
	if debug then print("Moonphase - Collecting data from: "..url) end
        os.execute('curl -s '..url..' > '..tempfilename)

        -- NOTE: if the command above doens't work in your situation try
        -- read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
        -- instead! Thanks to EdKo66
		
        file = io.open(tempfilename, "r")
        s= file:read("*a")
        s = (string.gsub(s, "%c+", ""))
        file:close()
 
        -- moonrise
        moonriseHour, moonriseMinute = string.match(s, [["moonrise": {"hour":"(%d+)","minute":"(%d+)"]])
        if moonriseHour == nil then moonriseHour = '--' end
        if moonriseMinute == nil then moonriseMinute = '--' end
        if debug then print("Moonrise:\t"..moonriseHour..":"..moonriseMinute) end
		
        -- moonset
        moonsetHour, moonsetMinute = string.match(s, [["moonset": {"hour":"(%d+)","minute":"(%d+)"]])
        if moonsetHour == nil then moonsetHour = "--" end
        if moonsetMinute == nil then moonsetMinute = "--" end
        if debug then print("Moonset:\t"..moonsetHour..":"..moonsetMinute) end
 
        -- percentage of moon illuminated
        percentIlluminated = string.match(s, [["percentIlluminated":"(%d+)"]])
        if debug then print("Percent:\t"..percentIlluminated.."%") end
 
        -- age of moon since last new moon
        age = string.match(s, [["ageOfMoon":"(%d+)"]])
        if debug then print("Age:\t\t"..age) end
 
        -- Phase of the moon
        -- set the moonPhaseIcon to your appropriate icon number (8 x)
        moonPhase = string.match(s, [["phaseofMoon":"(.-)"]])
        if moonPhase=="New Moon" then
            moonPhase = "Nieuwe maan"
            is_waxing = true
        end
        if moonPhase=="Waxing Crescent" then
            moonPhase = "Wassende halve maan"
            is_waxing = true
        end
        if moonPhase=="First Quarter" then
            moonPhase = "Eerste kwartier"
            is_waxing = true
        end
        if moonPhase=="Waxing Gibbous" then
            moonPhase = "Wassende maan"
            is_waxing = true
        end
        if moonPhase=="Full" then
            moonPhase = "Volle maan"
            is_waxing = false
        end
        if moonPhase=="Waning Gibbous" then
            moonPhase = "Afnemende maan"
            is_waxing = false
        end
        if moonPhase=="Last Quarter" then
            moonPhase = "Laatste kwartier"
            is_waxing = false
        end
        if moonPhase=="Waning Crescent" then
            moonPhase = "Afnemende halve maan"
            is_waxing = false
        end
 
        -- calculate moonphase picture
        if percentIlluminated == '0' then
            n='50'
        else
            if waardecheck==false then
                picnumber=math.floor(math.abs(percentIlluminated-100)/2)
                n=tostring(picnumber)
                if n.length==1 then
                    n='0'+n
                end
            else
                picnumber=math.floor(50+(percentIlluminated/2))
                if picnumber == 100 then
                  picnumber=99
              end
            end
            n=tostring(picnumber)
        end
        picture='moon.'..n..'.png'
        if debug then print('Picture number: '..n..' '..'Picture name: '..picture) end
 
        commandArray['Variable:'..checkvar]=moonPhase
        commandArray['Variable:'..moonpicture]=picture
        commandArray[1] = {['UpdateDevice'] = idxmoonphase.."|0|"..moonPhase}
        commandArray[2] = {['UpdateDevice'] = idxmoonrise.."|0|"..moonriseHour..":"..moonriseMinute}
        commandArray[3] = {['UpdateDevice'] = idxmoonset.."|0|"..moonsetHour..":"..moonsetMinute}
        commandArray[4] = {['UpdateDevice'] = idxmoonage.."|0|"..age}
        commandArray[5] = {['UpdateDevice'] = idxmoonpercentage.."|0|"..percentIlluminated}
    else
        if debug then print("MoonPhase - Update not allowed: Difference is "..timedifference(uservariables_lastupdate[checkvar]).." seconds") end
    end
 
return commandArray

Remark: this script is based on a script by alexsh1 [1]

As you can see there are some (dummy) devices that need to be created in Domoticz. 2 uservariables:

User variable Type
MoonPicture STRING
MoonphaseCheck STRING

and 5 devices:

Hardware Name Type Axislabel
Dummy Switch Moon up Text
Dummy Switch Moon under Text
Dummy Switch Moonpercentage Percentage
Dummy Switch Moon age Custom Sensor Days
Dummy Switch Moonphase Text


Now we have to write down the IDX numbers for the 7 devices we've just created.
We need these when we're going to edit the moon script.

Change the following lines with the according IDX in de moon script:

local idxmoonpercentage ='xxx'              -- Your virtual moon percentage illuminated Device ID
local idxmoonage ='xxx'                     -- Your virtual moon age Device ID
local idxmoonphase ='xxx'                   -- Your virtual moon phase Device ID
local idxmoonrise='xxx'                     -- Your virtual moon rise variable ID
local idxmoonset='xxx'                      -- Your virtual moon set variable ID


After that, change the other remaining parameters:

local checktime = 3600			-- check allowed every x seconds 3600 = 60 min. Check the wundergroud API limitation before changing this
local city = "<your town>" 		-- Your city for Wunderground API
local countryCode = "<YOUR COUNTRY CODE>"     -- Your country code for Wunderground API
local wuAPIkey = "<your key>" 	 	-- Your Weather Underground API Key
local DOMO_IP = "<your domo ip>" 	-- Domoticz ip address
local DOMO_PORT = "<your domo port>" 	-- Domoticz port
local tempfilename = '/var/tmp/phase.tmp' 	-- can be anywhere writeable (chmod 744)
local debug=false 			-- false, true for domoticz log


The last part is editing the CONFIG.js file from Dashticz v2.0 (/<dashticz folder>/custom/)
Add the next variable with the correct IDX number (IDX number from the user variable MoonPicture)

config['idx_moonpicture'] = IDX_Number; //index of the uservariabele MoonPicture


Add the buttons.moons parameter and place this in a block

buttons.moon = {width:12, isimage:true, refreshimage:60000, image: 'moon'}

columns[5] = {}
columns[5]['blocks'] = [buttons.buienradar, buttons.nunl, buttons.radio, buttons.moon]
columns[5]['width'] = 6;

Place now the moon script in the /domoticz/scripts/lua directory and let's go!


Module - Garbage Collector

If you want to have a block with next pickup dates for your garbage, add the following to CONFIG.js (/<dashticz v2 folder>/custom/), and change zipcode & housenumber to the correct data:

var config ={}
config['garbage_company'] = 'cure';
config['garbage_icalurl'] = 0;
config['garbage_zipcode'] = '1234AB';
config['garbage_street'] = 'vuilnisstraat';
config['garbage_housenumber'] = '1';
config['garbage_maxitems'] = '12';
config['garbage_width'] = '12';
config['garbage_hideicon'] = 0;


And define them in a columns like:

columns[1]['blocks'] = ['garbage']


Furthermore it's possible to define custom names and/or colors.
When you define other colors you have to use the ORIGINAL names!

var trashnames = {}
trashnames['Pmd woonwijk'] = 'PMD';
trashnames['Papier en karton'] = 'PAPIER';
trashnames['Gft'] = 'GFT'

var trashcolors = {}
trashcolors['Pmd woonwijk'] = 'Yellow';
trashcolors['Papier en karton'] = 'Blue'
trashcolors['Gft'] = 'Green';


If you don't like the colored kliko (trashcan) you can add the following variable:

var _DO_NOT_USE_COLORED_TRASHCAN = true;
Parameter Description
var _DO_NOT_USE_COLORED_TRASHCAN true; shows only a white kliko (trashcan)

New config since november 2017

Since november 2017 a new method for the garbage configuration is introduced, with the following config parameters the default colouring and naming can be overwritten. config['garbage_use_names'] can be enabled to use the name from the config, config['garbage_use_colors'] is for enabling the colouring of the whole line.

var config ={}
config['garbage_company'] = 'cure';
config['garbage_icalurl'] = 0;
config['garbage_zipcode'] = '1234AB';
config['garbage_street'] = 'vuilnisstraat';
config['garbage_housenumber'] = '1';
config['garbage_maxitems'] = '12';
config['garbage_width'] = '12';
config['garbage_hideicon'] = 0;
config['garbage'] = {
    gft: {kliko: 'green', code: '#375b23', name: 'GFT'},
    pmd: {kliko: 'orange', code: '#db5518', name: 'PMD'},
    rest: {kliko: 'grey', code: '#5e5d5c', name: 'Restafval'},
    papier: {kliko: 'blue', code: '#153477', name: 'Papier'},
    kca: {kliko: 'red', code: '#b21807', name: 'Chemisch afval'},
    brown: {kliko: 'brown', code: '#7c3607', name: 'Bruin'},
    black: {kliko: 'black', code: '#000000', name: 'Zwart'},
};
config['garbage_use_names'] = true;
config['garbage_use_colors'] = true;
config['garbage_icon_use_colors'] = true;
Parameter Description
config['garbage_use_names'] = true; true / false; shows name from config
config['garbage_use_colors'] = true; true / false; shows coloring for complete line
config['garbage_icon_use_colors'] = true; true / false; shows colored or only white trashcan

And define them in a columns like:

columns[1]['blocks'] = ['garbage']



Module - Calendar

You can add a block with upcoming events from your ical-calendar (gmail, apple etc.).
You have to add the following code into the CONFIG.js file and define them as:

var calendars = {}
calendars.business = { maxitems: 5, url: 'https://calendar.google.com/calendar/', icalurl: 'https://calendar.google.com/calendar/' }
calendars.private = { maxitems: 5, icalurl: 'https://calendar.google.com/calendar/' }


Where 'url' is the webaddress of the page to be shown when clicking the block.
'icalurl' is the webaddress to the ical-version of your calendar.

And define them in a column like:

columns[1] = {}
columns[1]['width'] = 2;
columns[1]['blocks'] = [calendars.business,calendars.private]


If you want to combine multiple calendars, add this code:

calendars.combined = {}
calendars.combined.maxitems = 5;
calendars.combined.calendars = [
   { color:'white',calendar:calendars.business }, 
   { color:'#ccc',calendar:calendars.private }
]
calendars.combined.url = 'https://calendar.google.com/calendar';


And define them in a column like:

columns[1] = {}
columns[1]['width'] = 2;
columns[1]['blocks'] = [calendars.combined]


Furthermore you can modify the date-formate and the local if the calendar is not displayed correct:

var _ICALENDAR_DATEFORMAT	= 'DD.MM.YYYY HH:mm'; //'friendly', 'MM.DD.YYYY HH:mm', 'DD.MM.YYYY HH:mm', 'YYYY.MM.DD HH:mm'
var _ICALENDAR_LOCALE		= 'nl'; //en,hu, etc.




Module - Public Transport

It is possible to show the timetable of the public transport company VVS (Germany) AND NS (Netherlands) with live data.

VVS: To call the function properly, you will need the correct station id from: https://efa-api.asw.io/api/v1/station/
So for Stuttgart Central Station the station id is 5006118.
Then add this to config.js:

var publictransport = {}
publictransport.hbf= { station: '5006118', title:'Trains', show_lastupdate:true, provider: 'VVS', icon: 'train', interval: 15, results: 5 };


9292.nl: First get the station id from http://api.9292.nl/0.1/locations?lang=nl-NL&q=eindhoven (Change eindhoven to your own search parameter).
Then copy the id!

//example station id: station-eindhoven
var publictransport = {}
publictransport.ovinfo= { station: 'station-eindhoven', title:'OV Info', show_lastupdate:true, provider: '9292', icon: 'train', results: 5 };
publictransport.ovinfotrain= { station: 'station-eindhoven', title:'Bus', show_lastupdate:true, provider: '9292-bus', icon: 'bus', results: 5 };
publictransport.ovinfobus= { station: 'station-eindhoven', title:'Trein', show_lastupdate:true, provider: '9292-train', icon: 'train', results: 5 };


The icon is simply font-awesome without fa, interval = time in seconds for refreshing the data, and results = number of shown results.
Also possible is to customize the width, but i would not change the value of 12 because of the size of the output.

Font size can be changed by adding this to your custom.css and change to your own preference:

.publictransport div {
    font-size: 13px; 
}




Radio Plugin

For those who like to listen to the radio on Dashticz v2.0, there is a Plugin available.
Add the following to your CONFIG.js:

var _STREAMPLAYER_TRACKS     = [
   {"track":1,"name":"Q-music","file":"http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3"},
   {"track":2,"name":"538 Hitzone","file":"http://vip-icecast.538.lw.triple-it.nl/WEB11_MP3"},
   {"track":3,"name":"Slam! NonStop","file":"http://stream.radiocorp.nl/web10_mp3"},
   {"track":4,"name":"100%NL","file":"http://stream.100p.nl/100pctnl.mp3"},
   {"track":5,"name":"StuBru","file":"http://mp3.streampower.be/stubru-high.mp3"},
   {"track":6,"name":"NPO Radio 1","file":"http://icecast.omroep.nl/radio1-bb-mp3"},
   {"track":7,"name":"Omroep Brabant","file":"http://streaming.omroepbrabant.nl/mp3"},
];

To enable, use the key: 'streamplayer' in the block definitions!

columns[2]['blocks'] = [1,4,'streamplayer']


Streamplayer.jpg



Run your own "crossorigin.me" proxy service (Advanced Users!)

In some cases the Newsfeed wouldn't load and you get NO results. You have to put https://crossorigin.me/ before the newsfeed-url.
You can also run your own "crossorigin.me" proxy service.

Install node & npm:

Install node & npm:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo curl -L https://www.npmjs.com/install.sh | sh

// https://github.com/technoboy10/crossorigin.me.git crossorigin   //
git clone https://github.com/technoboy10/crossorigin.me.git crossorigin
cd crossorigin
npm install
npm start

You need to make a startup script, so the service will start automatic after a reboot.

use: Edit/find port (8080 by default) in the index.js file.

http://127.0.0.1:8080/https://www.anything.com/




Module - Topbar

Added a topbar! Not only to give the dashboard more 'body' but also to add some new functions like a settings-icon. And maybe in the future things like notifications and stuff.

config['hide_topbar'] = 0;


Default there will be the name, clock and settings-button presented in the Topbar.
You can customize the Topbar with the following settings:

var columns = {}
columns['bar'] = {}
columns['bar']['blocks'] = ['logo','miniclock','settings']




Module - Spotify

Add a spotify block to your Dashboard.

Before you can use it, create an app on the spotify website: https://developer.spotify.com/my-applic ... ons/create

Title: Dashticz Description: whatever ;)

On the next page, copy "Client ID" to your CONFIG.js like:

var _CLIENTID_SPOTIFY = '1112f16564cf4f4dsd4cbe8b52c58a44';

At the same page, enter your dashticz-url in the Redirect URIs field, for example:'

http://192.168.1.3:8080/

DONT FORGET TO PUSH THE SAVE BUTTON!!
In CONFIG.js, add the block like:

columns[2] = {}
columns[2]['blocks'] = ['spotify']
columns[2]['width'] = 5;

Currently you can only change playlist, but more functions are coming!


Module - TV Guide (Dutch)

Dashticz-tv-guide.png

In config.js add:

var tvguide = {}
tvguide.dutch = { key:'dutch', icon: 'fa-television', width:12, channels: [1,2,3,4,31,46,92], maxitems: 10 }

Note: channels: [1,2,3] => 1,2 and 3 are ChannelID's FIND THE CHANNEL ID IN LIST BELOW:

"id":"65",
"name":"Animal Planet OUD",

"id":"403",
"name":"Goed TV",

"id":"412",
"name":"Film1 Premiere +1",

"id":"309",
"name":"3voor12 On Stage",

"id":"310",
"name":"3voor12 Portal",

"id":"429",
"name":"Oranje TV",

"id":"308",
"name":"3voor12 Central",

"id":"83",
"name":"3voor12",

"id":"1",
"name":"NPO 1",

"id":"2",
"name":"NPO 2",

"id":"3",
"name":"NPO 3",

"id":"4",
"name":"RTL 4",

"id":"31",
"name":"RTL 5",

"id":"36",
"name":"SBS 6",

"id":"460",
"name":"SBS 9",

"id":"46",
"name":"RTL 7",

"id":"37",
"name":"NET 5",

"id":"34",
"name":"Veronica",

"id":"92",
"name":"RTL 8",

"id":"413",
"name":"HISTORY",

"id":"472",
"name":"Crime + Investigation",

"id":"438",
"name":"TLC",

"id":"91",
"name":"Comedy Central",

"id":"29",
"name":"Discovery Channel",

"id":"18",
"name":"National Geographic",

"id":"24",
"name":"Film 1 Premiere",

"id":"435",
"name":"24 Kitchen",

"id":"5",
"name":"E&eacute;n",

"id":"6",
"name":"Canvas",

"id":"440",
"name":"Fox",

"id":"19",
"name":"Eurosport 1",

"id":"436",
"name":"Eurosport 2",

"id":"465",
"name":"RTL Z",

"id":"466",
"name":"Ziggo Sport",

"id":"148",
"name":"Fox Sports Eredivisie",

"id":"99",
"name":"Ziggo Sport Select",

"id":"419",
"name":"Ziggo Sport Golf",

"id":"420",
"name":"Ziggo Sport Racing",

"id":"417",
"name":"Extreme Sports Channel",

"id":"411",
"name":"Film1 Action",

"id":"468",
"name":"Fox Sport 2",

"id":"469",
"name":"Fox Sport 3",

"id":"470",
"name":"Fox Sport 4",

"id":"39",
"name":"Film1 Family",

"id":"107",
"name":"Film 1 Sundance",

"id":"462",
"name":"Shorts TV",

"id":"407",
"name":"OUTTV",

"id":"430",
"name":"Film1 Drama",

"id":"408",
"name":"RTL Lounge",

"id":"409",
"name":"Rtl crime",

"id":"317",
"name":"Comedy Family",

"id":"437",
"name":"Comedy Central Extra",

"id":"104",
"name":"BBC Entertainment",

"id":"464",
"name":"BBC First",

"id":"315",
"name":"CBS Reality",

"id":"473",
"name":"Viceland",

"id":"404",
"name":"FOXlife",

"id":"25",
"name":"MTV",

"id":"427",
"name":"MTV Brand new",

"id":"428",
"name":"Brava NL",

"id":"89",
"name":"Nickelodeon",

"id":"21",
"name":"Cartoon Network",

"id":"424",
"name":"Disney Channel",

"id":"311",
"name":"Disney XD",

"id":"312",
"name":"Nick Jr.",

"id":"313",
"name":"Boomerang",

"id":"461",
"name":"Pebble TV",

"id":"416",
"name":"Nat Geo Wild",

"id":"415",
"name":"Travel Channel",

"id":"471",
"name":"KPN presenteert ",

"id":"306",
"name":"Discovery Science",

"id":"406",
"name":"Ons",

"id":"305",
"name":"Discovery World",

"id":"414",
"name":"Investigiation discovery",

"id":"439",
"name":"Animal Planet",

"id":"64",
"name":"NPO Zapp Xtra \/ NPO Best",

"id":"70",
"name":"NPO Cultura",

"id":"38",
"name":"ARTE",

"id":"26",
"name":"CNN",

"id":"422",
"name":"Euronews",

"id":"86",
"name":"BBC World",
"name_short":"BBC W"

"id":"423",
"name":"Al Jazeera Engels",

"id":"108",
"name":"RTV Noord",

"id":"109",
"name":"Omrop Frysl&acirc;n",

"id":"110",
"name":"RTV Drenthe",

"id":"111",
"name":"RTV Oost",

"id":"112",
"name":"Omroep Gelderland",

"id":"113",
"name":"Omroep Flevoland",

"id":"103",
"name":"NH",

"id":"100",
"name":"RTV Utrecht",

"id":"101",
"name":"RTV West",
"name_short":"RTV West"

"id":"102",
"name":"RTV Rijnmond",

"id":"116",
"name":"Omroep Zeeland",
"name_short":"Zeeland"

"id":"114",
"name":"Omroep Brabant",

"id":"115",
"name":"L1 TV",

"id":"40",
"name":"AT 5",

"id":"401",
"name":"Playboy TV",

"id":"434",
"name":"Dusk",

"id":"105",
"name":"Private Spice",

"id":"410",
"name":"101 TV",

"id":"90",
"name":"BVN",

"id":"7",
"name":"BBC 1",

"id":"8",
"name":"BBC 2",

"id":"301",
"name":"BBC 4",

"id":"60",
"name":"VT4",

"id":"49",
"name":"VTM",

"id":"59",
"name":"2BE",

"id":"15",
"name":"RTBF La 1",

"id":"16",
"name":"RTBF La 2",

"id":"17",
"name":"TV 5",

"id":"9",
"name":"ARD",

"id":"10",
"name":"ZDF",

"id":"12",
"name":"WDR Fernsehen",

"id":"13",
"name":"NDR Fernsehen",

"id":"11",
"name":"RTL",

"id":"28",
"name":"Sat 1",

"id":"50",
"name":"3Sat",

"id":"58",
"name":"PRO 7",

"id":"32",
"name":"TRT int.",

"id":"467",
"name":"Spike",

"id":"304",
"name":"AMC",




Module - NZBget

Show your current downloads within the Dashboard.

Add to config.js:

var _HOST_NZBGET = 'http://192.168.1.3:6789';


AND in the blocks, add:

columns[1]['blocks'] = ['nzbget']


If you want to use other widths, add this to config:

blocks['nzbget'] = {}
blocks['nzbget']['width'] = 12;
blocks['nzbget']['downloads_width'] = 6;




Module - Sonarr

- UPDATE FOLLOWS -




Dv2-home.png
Dashticz V2.0 Main Page