2024-01-13
md
Domoticz Tips, Tricks & Info

This is just a list of tips and tricks that I find useful and decided to compile for easy retrieval. Most of these were found in the

I tried to attribute these snippets to the original source. If I came up with something myself, no source is given. My apologies to all those that published something along the same line before.

I have just come across a "cookbook", Domoticz Home Automation Workbook by Robert W.B. Linn. It contains a great number of recipes and the author continues to update this work. Highly recommended. Track the GitHub repository to always get the newest edition.

How to

  1. Add Custom Switch Icons
  2. Add Custom Switch Icons Saved in the Domoticz Database
  3. Add a Web Interface Theme
  4. Change a Virtual Sensor Label / Rename a Device Using a JSON API
  5. Clear a Custom Sensor Log with sqlite
  6. Clear a Scene Log with a JSON API
  7. Clear a Switch Log with a JSON API
  8. Clear a Text Log with a JSON API
  9. Delete a Record in a Device with Graphic Log
  10. Display Timer Plans in Settings
  11. Enable Scripts Executing System Calls Requiring Root Privileges
  12. Get the Domoticz Icon
  13. Get the Domoticz Source Code
  14. Manage and Select Timer Plans
  15. Retrieve a Scene Log with a JSON API
  16. Repair a "database disk image is malformed" Error with sqlite
  17. Select a Timer Plan with a JSON API
  18. Start Domoticz as a systemd Service

How to Add Custom Switch Icons toc

Source: DIY Projects
Title: Domoticz: give a facelift by customizing the icons
URL: https://diyprojects.io/domoticz-give-facelift-customizing-icons/
Tested: 2019-10-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. Select a name for the icon (in this example MyIcon)
  2. Create three png icons with transparent backgrounds:
    • A 48x48 pixel ON image named "MyIcon48_ON.png"
    • A 48x48 pixel OFF image named "MyIcon48_OFF.png"
    • A 16x16 pixel ON image named "MyIcon.png"
    The 16x16 image is used on floor plans, the 48x48 images are used on device panels in the Web interface.
  3. Upload the three files to ~/domoticz/www/images on the Domoticz server.
  4. Add a line at the end of the ~domoticz/www/switch_icons.txt file. It should contain three fields separated by a semi-colon ";"
      MyIcon;My icon;This is my icon
    The first field is the name of the icon (step 1).
    The second field is the bold caption shown in the list of icons
    The third field is the additional grey text shown in the list
The images will not be saved in the Domoticz database.

How to Add Custom Switch Icons Saved in the Domoticz Database toc

Source: Domoticz Wiki
Title: Custom icons for webinterface
URL: https://www.domoticz.com/wiki/Custom_icons_for_webinterface
Tested: 2019-10-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: Create Icon Archive which can contain icons for one or more switch
  1. For each switch select a name for the icon (in this example MyIcon)
  2. For each switch create three png icons with transparent backgrounds:
    • A 48x48 pixel ON image named "MyIcon48_ON.png"
    • A 48x48 pixel OFF image named "MyIcon48_OFF.png"
    • A 16x16 pixel ON image named "MyIcon.png"
    • The 16x16 image is used on floor plans, the 48x48 images are used on device panels.
  3. Create the icons.txt file
  4. For each switch add a line in the icon.txt file. Each line must contain three fields separated by a semi-colon ";"
      MyIcon;My icon;This is my icon
    The first field is the name of the icon (step 1).
    The second field is the bold caption shown in the list of icons
    The third field is the additional grey text shown in the list
  5. Add all files (3 x number of switches image files + 1 text file) to an archive
Upload Icon archive
  1. Setup tab
  2. More Options
  3. Custom Icons
  4. Browse to the icon archive
  5. Click Upload button
The images will be saved in the Domoticz database.
Note Saving images for one and two device icons in an archive worked without problem, but there were problems with three device icons in an archive.

How to Add a Web Interface Theme toc

Source: Domoticz Forum, blauwebuis
Title: Aurora theme
URL: https://www.domoticz.com/forum/viewtopic.php?f=8&t=20960
Tested: 2019-10-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. pi@raspberrrypi:~ $ wget https://github.com/flatsiedatsie/domoticz-aurora-theme/archive/master.zip
  2. pi@raspberrrypi:~ $ unzip master.zip
  3. pi@raspberrrypi:~ $ mkdir domoticz/www/styles/aurora
  4. pi@raspberrrypi:~ $ cp -r domoticz-aurora-theme-master/* domoticz/www/styles/aurora
  5. pi@raspberrrypi:~ $ rm -r domoticz-aurora-theme-master/
  6. pi@raspberrrypi:~ $ mv master.zip downloads/domoticz-aurora-theme.zip
  7. In domoticz: Setup/Settings/System/Theme: aurora
  8. In domoticz: Apply Settings

How to Change a Virtual Sensor Label / Rename a Device Using JSON API toc

Source: Domoticz Wiki
Title: Domoticz API/JSON URL's, 7.5 Rename device / sensor
URL: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Rename_device_.2F_sensor
Tested: 2019-05-21
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. Get idx of sensor: {sensor_idx}
  2. Get host name or IP address of Domoticz server: {hostname_or_ip}
  3. Get Domoticz TCP port: {port}
  4. Send http request = http://{host_name_or_ip}:{port}/json.htm?type=setused&idx={sensor_idx}&name={new_label}&used=true
Examples:
http://192.168.1.22:8080/json.htm?type=setused&idx=93&name=Today+is+Monday&used=true
http://192.168.1.22:8080/json.htm?type=setused&idx=93&name=Date:<span+style="float:+right;+font-weight:+bold">2019-10-31</span>&used=true
Note: Additional right justified text cannot be used with sensors, such as switches, temperature and other weather sensors that already display more than the sensor name. It works with text sensors as shown in the second example above.

How to Clear a Custom Sensor Log with sqlite toc

Source: Frustration Memory, Arjan
Title: Correcting values in Domoticz database
URL: https://frustrationmemory.blogspot.com/2017/04/correcting-values-in-domoticz-database.html
Tested: 2019-11-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. Install sqlite3 on desktop machine:
    $ sudo apt install sqlite3
  2. Make a backup copy of the Domoticz database on the desktop computer. Do this from the Domoticz Web interface: SetupSettingsBackup/RestoreBackup Database. Keep track of where Domoticz.db was saved. Assume from now on that it was in /home/michel/temp alias ~/temp.
  3. Make a backup of the backup just in case:
    $ cp temp/Domoticz.db temp/Domoticz.bak
  4. Open the database in sqlite3
    $ sqlite3 temp/Domoticz.db
    SQLite version 3.22.0 2018-01-22 18:45:57
    Enter ".help" for usage hints.
  5. Issue a few commands that will make the display clearer.
    sqlite> .header on
    sqlite> .mode column
    
  6. Use the SELECT command to find the custom sensor data. This assumes that the custom sensor index number is 165.
    sqlite> SELECT * FROM Percentage WHERE [DeviceRowID] = 165;
    DeviceRowID  Percentage  Date
    -----------  ----------  -------------------
    165          5.0         2019-11-17 13:00:00
    165          5.0         2019-11-17 13:05:00
    ...
  7. Delete all entries for the device from the Percentage table.
    sqlite> DELETE FROM Percentage WHERE [DeviceRowID] = 165;
    
  8. Delete all entries for the decive from the Percentage_Calendar table.
    sqlite> DELETE FROM Percentage_Calendar WHERE [DeviceRowID] = 165;
    
  9. Check that the entries were deleted.
    sqlite> SELECT * FROM Percentage WHERE [DeviceRowID] = 165;
    sqlite> SELECT * FROM Percentage_Calendar WHERE [DeviceRowID] = 165;
    
  10. Quit sqlite3.
    sqlite> .quit
    
  11. Restore the modified database from the Domoticz Web interface: SetupSettingsBackup/RestoreRestore Database.
  12. If something is wrong, restore the backup database Domoticz.bak
Note Instead of deleting all entries, data could be modified. See the source for details.
Note It is possible to delete a single record from logged data in the Domoticz Web interface; there must be a similar way of clear a log, but I have not found it.

How to Clear a Scene Log with a JSON API toc

Source:
Title:
URL:
Tested: 2019-11-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: Assuming the index of the scene is 8, send an HTTP request to the Domoticz server such as
http://192.168.1.22:8080/json.htm?type=command&param=clearscenelog&idx=8
This can be done from a browser:

How to Clear a Switch Log with a JSON API toc

Source: Domoticz Wiki
Title: History / Switch devices / Delete
URL: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Delete
Tested: 2019-11-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: Send an HTTP request to the Domoticz server:
http://<DOMOTICZ_IP>:<DOMOTICZ_PORT>/json.htm?type=command&param=clearlightlog&idx=<SWITCH_IDX>
Assuming the switch index is 12 and the Domoticz server IP is 192.168.1.22 and that the default port is used, then the request
http://192.168.1.22:8080/json.htm?type=command&param=clearlightlog&idx=12
will clear the switch log. This can be done from a browser:

How to Clear a Text Log with a JSON API toc

Source: Domoticz Wiki
Title: History / Text devices / Delete
URL: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Delete_2
Tested: 2019-11-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: Send an HTTP request to the Domoticz server:
http://<DOMOTICZ_IP>:<DOMOTICZ_PORT>/json.htm?type=command&param=clearlightlog&idx=<TEXT_IDX>
This the same for clearing a switch log.

How to Delete a Record in a Device with Graphic Log toc

Source: Michael Visser (Visser I/O)
Title: How to delete an erroneous device record in Domoticz
URL: https://visser.io/2017/04/how-to-delete-an-erroneous-device-record-in-domoticz/
Tested: 2019-10-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. Open up Domoticz in your preferred web browser
  2. Open up the device log screen for the device in question (in my case a Utility device)
  3. With your mouse hover over the bad reading
  4. Hold down SHIFT on your keyboard and left click the bad reading
  5. A confirmation screen will appear, check the date/time and value is the bad value and hit OK

How to Display Timer Plans in Settings toc

Source: dragonpi
Title: Re: Timer Plan is empty in settings
URL: https://www.domoticz.com/forum/viewtopic.php?f=6&t=25180&p=193857&hilit=timer+plan#p224044
Tested: 2019-10-19
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: If nothing displayed: press F5

How to Enable Scripts Executing System Calls Requiring Root Privileges toc

Source: DomoticzCH; waaren,
Title: Restart/Shutdown when running as non root user; Re: Script to fire a command to a router through SSH
URL: https://www.domoticz.com/forum/viewtopic.php?p=275337#p275337; https://www.domoticz.com/forum/viewtopic.php?p=232883#p232883
Tested: 2022-06-22
Domoticz: 2021.1 (build 13330)
How:
  1. Make sure that the Domoticz user (usually pi) is a member of the sudo group.
    pi@raspberrypi:~ $ groups pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
  2. Add the following line after the similar line beginning with %sudo in /etc/sudoers
    pi ALL=(ALL:ALL) NOPASSWD: ALL
    with the visudo utility:
    pi@raspberrypi:~ $ visudo
  3. Alternatively create the file
    pi@raspberrypi:~ $ visudo -f /etc/sudoers.d/pi-no-passwd
    containing that single line.
Note In Linux, a Domoticz launched script that executes a system call requiring root privileges will only work if
  • the user is a member of the sudo group and if
  • a password is not required for the user.

For example, the script script_time_domoticzAlive.lua with the following command

os.execute('sudo touch /tmp/domoticz.alive')
would not be executed properly because the sudo touch command wants the password for user pi even if pi is a member of the sudo group. Here is the system log entry showing the error.
Jun 22 18:13:00 raspberrypi domoticz[375]: sudo: no tty present and no askpass program specified Jun 22 18:13:00 raspberrypi sudo[1832]: pam_unix(sudo:auth): conversation failed Jun 22 18:13:00 raspberrypi sudo[1832]: pam_unix(sudo:auth): auth could not identify password for [pi] Jun 22 18:13:00 raspberrypi domoticz[375]: 2022-06-22 18:13:00.471 Status: LUA: script_time_domoticzAlive.lua

How to Get the Domoticz Icon toc

Source:
Title:
URL:
Tested: 2024-01-13
Domoticz: n/a
How: Download domoticz.ico from the following link https://raw.githubusercontent.com/domoticz/domoticz/development/msbuild/domoticz.ico.There are numerous ways of downloading the .ico file.
  1. Click on the image with the right mouse button. Choose to save the image file in the context menu. The exact label of the menu choice will depend on the browser used.
  2. wget "https://raw.githubusercontent.com/domoticz/domoticz/development/msbuild/domoticz.ico"
  3. curl "https://raw.githubusercontent.com/domoticz/domoticz/development/msbuild/domoticz.ico" -o domoticz.ico
Notes:
  • An even bigger 400×400 pixels png image is available here.
  • The ico file contains five images in the "usual" dimensions: 256×256, 128×128, 64×64, 32×32, and 16×16 pixels.
  • If the domoticz.ico file is opened in GIMP all five images will be seen as superimposed. This is because each image is placed on a separate layer, but they are all visible. Each image can be exported as a .png, .jpeg or other format image file, by making its layer the only visible one and the use the File / Export As... (shortcut: ShiftCtrlS).
  • One could also download the favicon.ico image from the running instance of Domoticz.
    wget http://<DOMOTICZ_IP>:<DOMOTICZ_PORT>/favicon.ico
    
    However that file contains only the 32×32 and 16×16 pixels images.

How to Get the Domoticz Source Code toc

Source:
Title:
URL:
Tested: 2024-01-13
Domoticz: n/a
How: The source code is available in the GitHub Repository: https://github.com/domoticz/domoticz. Here are some methods to retrieve the code.
  1. The repository can be cloned if git is installed on the computer. Use the address https://github.com/domoticz/domoticz.git
  2. Click on the Download ZIP link in the pop-up window displayed when the <> Code v button is pressed.
  3. Go to the latest release and download the Source code as a zip or tar.gz archive.

How to Manage and Select Timer Plans toc

Source:
Title:
URL:
Tested: Latest: 2024-01-13. Original: 2019-10-18
Domoticz: Latest: 2023.2, Build Hash: 19efd039c, Date: 2023-07-21 12:23:44. Original: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: Create, delete, rename timer plans
  1. Click on the Setup tab
  2. Click on More Options
  3. Click on Plans
  4. Click on TimerPlan (if nothing visible press F5)
Select a timer plan
  1. Click on the Setup tab
  2. Click on Settings
  3. Click on Other
  4. Select the desired plan in the Timer Plan: combo box.
  5. Click on Apply Settings

How to Repair a "database disk image is malformed" Error with sqlite3 toc

Source: Domoticz Forum, Flopp
Title: FIX for The database disk image is malformed
URL: https://www.domoticz.com/forum/viewtopic.php?f=28&t=10984
Tested: 2020-05-31
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. Install sqlite3 on desktop machine:
    $ sudo apt install sqlite3
  2. Make a backup copy of the Domoticz database on the desktop computer. Do this from the Domoticz Web interface: SetupSettingsBackup/RestoreBackup Database. Keep track of where Domoticz.db was saved. Assume from now on that it was in /home/michel/temp alias ~/temp.
  3. Make a backup of the backup just in case:
    $ cp temp/Domoticz.db temp/Domoticz.bak
  4. Open the database in sqlite3
    $ sqlite3 temp/Domoticz.db
       SQLite version 3.22.0 2018-01-22 18:45:57
       Enter ".help" for usage hints.
  5. A list of errors can be displayed.
    sqlite> pragma integrity_check;
       *** in database main ***
       On tree page 116 cell 69: Rowid 13668 out of order
       On tree page 409 cell 26: 2nd reference to page 483
       ...
       row 50 missing from index ll_id_date_idx
       row 51 missing from index ll_id_date_idx
  6. Dump the database.
    sqlite>  .output dump.sql
       sqlite>  .dump
       sqlite>  .exit
  7. Using a text editor change the last line in ~/temp/dump.sql from
    ROLLBACK; -- due to errors
    to
    COMMIT;
  8. Re-create the database.
    $ sqlite3 temp/fixed.db < temp/dump.sql
  9. Test that the fixed database is ok.
  10. $ sqlite3 temp/fixed.db
       sqlite> pragma integrity_check;
       ok
  11. Quit sqlite3.
    sqlite> .quit
  12. Restore the fixed database (~/temp/fixed.db) using the Domoticz Web interface: SetupSettingsBackup/RestoreRestore Database.
  13. If something is wrong, restore the backup database Domoticz.bak

How to Retrieve a Scene Log with a JSON API toc

Source:
Title:
URL:
Tested: 2019-11-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: Assuming the index of the scene is 8, send an HTTP request to the Domoticz server such as
http://192.168.1.22:8080/json.htm?type=scenelog&idx=8
This can be done from a browser:

How to Select a Timer Plan With the JSON API toc

Source: broxtor
Title: Re: Use switch to disable setpoint timers [Solved]
URL: https://www.domoticz.com/forum/viewtopic.php?f=59&t=28361&p=217753&hilit=setactivetimerplan#p217753
Tested: 2019-10-18
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How: http://<host_ip:port>/json.htm?type=command&param=setactivetimerplan&ActiveTimerPlan=<n> where <n> is the index of the plan. Usually plan Default is 0.
Note If this is the action of a selector switch for example, then the Switches tab is not refreshed so the Timers button are not updated. Conversely, selecting a TimerPlan in Setup/Settings/Other will not update the value of the selector switch.

How to Start Domoticz as a systemd Service toc

Source:
Title:
URL:
Tested: 2019-12-08
Domoticz: 4.10717, Build Hash: b38b49e5, Date: 2019-05-09 08:04:08
How:
  1. Create the unit file /etc/systemd/system/domoticz.service.
  2. [Unit] Description=domoticz_service After=time-sync.target [Service] User=pi Group=users ExecStart=/home/pi/domoticz/domoticz -www 8080 -sslwww 443 WorkingDirectory=/home/pi/domoticz AmbientCapabilities=CAP_NET_BIND_SERVICE Restart=on-failure RestartSec=1m [Install] WantedBy=multi-user.target
  3. Stop the Domoticz service
  4. Delete the old init script /etc/init.d/domoticz.sh
  5. Reload daemons
  6. Start the Domoticz service
  7. Enable the service for auto starting at boot.
Note The After=time-sync.target condition will guarantee that the system time is updated before starting Domoticz. This avoids the startup crash that happens when restarting systems without a functioning real time clock that have been down for more than six minutes or so. See The Domoticz Time Synchronization Problem.