SQL-problem

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

SQL-problem

Post by BartSr »

I use this query in a dzVents script of late Waaren ( viewtopic.php?t=30725 )

collects.meters = 'SELECT a.ID Meter, a.Name Name, b.Value Value, b.Usage Usage, b.Date Date '..

' FROM DeviceStatus a , Meter b WHERE AND a.ID = b.DeviceRowID AND a.ID IN (' .. allMeters .. ')'
of course this is OK.

Now I modified to limit to output using:

collects.meters = 'SELECT a.ID Meter, a.Name Name, b.Value Value, b.Usage Usage, b.Date Date '..

' FROM DeviceStatus a , Meter b WHERE time(b.Date) = "07:00:01" AND a.ID = b.DeviceRowID AND a.ID IN (' .. allMeters .. ')'

note extended where-clause : time(b.Date) = "07:00:01" AND

But ....
When I create the query in DB Browser for SQLite it's OK. Output as expected.
Same query in Domoticz scripts: no output. Logfile shows ERROR ==>> but no errormessage.
Anyone who knows how to solve?

Thanks.
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
willemd
Posts: 741
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: SQL-problem

Post by willemd »

"time" is probably not a function known within dzVents. You will have to use a different method to get the time part of the date field that you selected, depending on what type the date field is. Probably a string?
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

Re: SQL-problem

Post by BartSr »

Date is datetime type. So how to get the timeselectio?
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
willemd
Posts: 741
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: SQL-problem

Post by willemd »

User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: SQL-problem

Post by waltervl »

the time statement is in the SQL query so no DzVents option.
I think it has to do with formatting the string and DzVents gets confused? Try to play with quote ' and double quotes "

Code: Select all

collects.meters = 'SELECT a.ID Meter, a.Name Name, b.Value Value, b.Usage Usage, b.Date Date FROM DeviceStatus a , Meter b WHERE time(b.Date) = "07:00:01" AND a.ID = b.DeviceRowID AND a.ID IN (' .. allMeters .. ')'
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

Re: SQL-problem

Post by BartSr »

Hi Waltervl,
Quotes, double quotes and square quotes. All the same.
Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
willemd
Posts: 741
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: SQL-problem

Post by willemd »

and what about a backslash before the double quotes before and after the time ( so \"07:00:01\" ), to indicate to dzVents these should not be treated as double quotes but just past as is.
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: SQL-problem

Post by waltervl »

Also there is a colon ":" in the string (due to the time 7:00:00 ) that perhaps mixes things up in lua table collects{}???
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest