Putting a db value in a counter

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
Post Reply
chrispazz
Posts: 86
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Putting a db value in a counter

Post by chrispazz » Saturday 15 September 2018 13:00

Hello,
I have a table in a MariaDB with a specific value that I can read using a specific SQL query.

Which is the fastest way to expose this value in domoticz and also save the history of changes?
Someone has some script examples?

Thank you
Chris

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Putting a db value in a counter

Post by ben53252642 » Saturday 15 September 2018 13:10

Probably a PHP or Bash script then send the data to a Domoticz device using the JSON API.

https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's

Depending on coding skill, Node-Red is another option, you could use MQTT to communicate with Domoticz.

Example bash script

Code: Select all

#!/bin/bash

# Domoticz Configuration
domoticzserver="192.168.0.5"
domoticzport="443"
domoticzuser="USERNAME"
domoticzpass="PASSWORD"

# Get the SQL data
sql=$(YOURCOMMANDTOGETTHEVALUEHERE)

# Send data to Domoticz
curl --max-time 60 -k -s "https://{$domoticzuser}:{$domoticzpass}@{$domoticzserver}:{$domoticzport}/json.htm?type=command&param=udevice&idx=1128&nvalue=0&svalue={$sql}"
Hope this helps.

chrispazz
Posts: 86
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Putting a db value in a counter

Post by chrispazz » Saturday 15 September 2018 15:08

Great, your advice works great.
Which is the correct device type to use to have actual (last) value and also be able to check previous logged values history?

Thank you again!

BugsBob
Posts: 7
Joined: Monday 10 September 2018 18:15
Target OS: Windows
Domoticz version:
Location: Tampa, Florida

Re: Putting a db value in a counter

Post by BugsBob » Tuesday 18 September 2018 17:48

Thanks for that, Ben! Will take note of it for future reference.

By the way, newbie here. I'm glad to have found this great online open source/home automation community. I joined up in the hopes of learning a thing or two from the other members here. Whenever I'm taking a break from this particular interest, I'm usually found at home, treating my Pomeranian to his dog bone and watching TV with my wife. Such a simple, yet, happy life. Cheers, everyone!
Last edited by BugsBob on Friday 21 September 2018 16:12, edited 1 time in total.

chrispazz
Posts: 86
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Putting a db value in a counter

Post by chrispazz » Tuesday 18 September 2018 17:52

Yes!

Finally I used the Percentage indicator that is also storing the history values.

:)

ben53252642
Posts: 524
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Putting a db value in a counter

Post by ben53252642 » Tuesday 18 September 2018 18:47

chrispazz wrote:
Tuesday 18 September 2018 17:52
Yes!

Finally I used the Percentage indicator that is also storing the history values.

:)
Can you post a code example? I'm interested to see how you accessed previous data.

Thanks

chrispazz
Posts: 86
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Putting a db value in a counter

Post by chrispazz » Wednesday 19 September 2018 9:07

There is no script.
I update a Virtual switch (Percentage) using json.
It shows the last percentage and also show the history within the log.

:)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests