Page 1 of 1
How to get Text from sensor
Posted: Saturday 20 October 2018 14:06
by misko903
Hi everyone,
I have installed a virtual HW to predict the weather. Darksky.
I want to include the text from sensor to message sent to my phone every morning.
For now, I am able to send only value of temperature and humidity, but not the text under the values of the sensor - prediction.
How to do it? Is there any spec value, or should I create a virtual switch, or...?
Thank you,
Michal, SVK
Re: How to get Text from sensor
Posted: Saturday 20 October 2018 16:21
by waaren
misko903 wrote: Saturday 20 October 2018 14:06
Hi everyone,
I have installed a virtual HW to predict the weather. Darksky.
I want to include the text from sensor to message sent to my phone every morning.
For now, I am able to send only value of temperature and humidity, but not the text under the values of the sensor - prediction.
How to do it? Is there any spec value, or should I create a virtual switch, or...?
Thank you,
Michal, SVK
What is the type / subtype of this device? (can be found at the devices tab)
Re: How to get Text from sensor
Posted: Saturday 20 October 2018 20:41
by misko903
This:
Temp + Humidity + Baro
THB1 - BTHR918, BTHGN129
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 1:13
by waaren
misko903 wrote: Saturday 20 October 2018 20:41
Temp + Humidity + Baro
THB1 - BTHR918, BTHGN129
OK,
can you try this
Code: Select all
return {
on = { timer = { "at 08:00"}},
execute = function(dz)
local myDevice = dz.devices(1103) -- change this to the ID of your device or the name in quotes
local degree = '°'
local notifyString = "Today it will be " .. myDevice.forecastString ..
" (" .. myDevice.barometer .." hPa). The expected temperature will be " ..
myDevice.temperature .. degree .. " and the humidity will feel as " .. myDevice.humidityStatus
dz.log(notifyString:gsub(degree," degrees"))
dz.notify(notifyString)
end
}
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 11:14
by Joep123
Thanks for sharing the script Waaren!
I get an dzEvents error.
Code: Select all
2018-10-21 11:02:00.457 Status: dzVents: Info: ------ Start internal script: weerbericht:, trigger: at 11:02
2018-10-21 11:02:00.458 Status: dzVents: Error (2.4.7): Today it will be Partly Cloudy (1029 hPa). The expected temperature will be 10 degrees and the humidity will feel as Wet
2018-10-21 11:02:00.458 Status: dzVents: Info: ------ Finished weerbericht
2018-10-21 11:02:00.630 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-10-21 11:02:00.656 Status: Notification: Today it will be Partly Cloudy (1029 hPa). The expected temperature will be 10° and the humidity will feel as Wet
2018-10-21 11:02:00.656 Notification sent (email) => Success
2018-10-21 11:02:01.219 Notification sent (telegram) => Failed
2018-10-21 11:02:01.544 Notification sent (pushover) => Success
2018-10-21 11:02:01.219 Error: Telegram: {"ok":false,"error_code":400,"description":"Bad Request: message must be non-empty"}
According to the log the notification sent by email and pushover will be fine but I didn't receive any message.
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 19:19
by misko903
Thanks Waaren,
for me it works!!! the only thing is the accuracy - lenght of the temperatures - 10.39999961853°
Code: Select all
2018-10-21 18:27:00.317 Status: dzVents: Info: ------ Start internal script: Pokus SenzorText:, trigger: at 18:27
2018-10-21 18:27:00.332 Status: dzVents: Error (2.4.6): Today it will be Sunny (1026 hPa). The expected temperature will be 10.39999961853 degrees and the humidity will feel as Wet
2018-10-21 18:27:00.332 Status: dzVents: Info: ------ Finished Pokus SenzorText
2018-10-21 18:27:00.428 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-10-21 18:27:00.436 Status: LUA: Domoticz alive !
2018-10-21 18:27:00.448 Status: Notification: Today it will be Sunny (1026 hPa). The expected temperature will be 10.39999961853° and the humidity will feel as Wet
2018-10-21 18:27:01.050 Notification sent (gcm) => Success
2018-10-21 18:27:03.397 Notification sent (email) => Success
Now I will try to set it up every morning before I will step in the car.
Plus how can I send the notifications
only throug a specific service - for example gcm (not gmail)?
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 21:14
by waaren
misko903 wrote: Sunday 21 October 2018 19:19
for me it works!!! the only thing is the accuracy - lenght of the temperatures - 10.39999961853°
Plus how can I send the notifications
only throug a specific service - for example gcm (not gmail)?
Please check the improved version
Code: Select all
return {
on = { timer = { "at 08:00"}},
execute = function(dz)
local myDevice = dz.devices(1103) -- change this to the ID of your device or the name in quotes
local toLog = true -- switch between true/false when you want/don't want an entry in logfile
local email = false -- switch between true/false when you want/don't want to be Emailed
local notify = true -- switch between true/false when you want/don't want a notification
local myNotificationTable = {dz.NSS_GOOGLE_CLOUD_MESSAGING, dz.NSS_PUSHOVER} -- table with one or more notification system. Can be one or more of
-- dz.NSS_GOOGLE_CLOUD_MESSAGING,
-- dz.NSS_HTTP,
-- dz.NSS_KODI,
-- dz.NSS_LOGITECH_MEDIASERVER,
-- dz.NSS_NMA,
-- dz.NSS_PROWL,
-- dz.NSS_PUSHALOT,
-- dz.NSS_PUSHBULLET,
-- dz.NSS_PUSHOVER,
-- dz.NSS_PUSHSAFER
local degree = '°'
local notifyString = "Today it will be " .. myDevice.forecastString ..
" (" .. myDevice.barometer .." hPa). The expected temperature will be " ..
dz.utils.round(myDevice.temperature,1) .. degree .. " and the humidity will feel as " .. myDevice.humidityStatus
if toLog then dz.log(notifyString:gsub(degree," degrees"),dz.LOG_INFO) end
if email then dz.email("Weather forecast",notifyString,"[email protected]") end
if notify then dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable ) end
end
}
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 21:20
by waaren
Joep123 wrote: Sunday 21 October 2018 11:14
I get an dzEvents error.
According to the log the notification sent by email and pushover will be fine but I didn't receive any message.
Please check the improved version
here
If the log show that the notification has been sent and you don't receive anything, I suspect the problem in the domoticz notification setup area.
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 23:26
by Joep123
Also with the improved version it doesn't work for me:
Code: Select all
2018-10-21 23:22:00.334 Status: dzVents: Info: ------ Start internal script: weerbericht:, trigger: at 23:22
2018-10-21 23:22:00.335 Status: dzVents: Error (2.4.7): An error occured when calling event handler weerbericht
2018-10-21 23:22:00.335 Status: dzVents: Error (2.4.7): /home/pi/domoticz/dzVents/runtime/Domoticz.lua:163: attempt to perform arithmetic on local 'x' (a nil value)
2018-10-21 23:22:00.335 Status: dzVents: Info: ------ Finished weerbericht
Pushover settings are fine, I receive notifications from other scripts...
Re: How to get Text from sensor
Posted: Sunday 21 October 2018 23:54
by waaren
Joep123 wrote: Sunday 21 October 2018 23:26
Also with the improved version it doesn't work for me:
Code: Select all
2018-10-21 23:22:00.334 Status: dzVents: Info: ------ Start internal script: weerbericht:, trigger: at 23:22
2018-10-21 23:22:00.335 Status: dzVents: Error (2.4.7): An error occured when calling event handler weerbericht
2018-10-21 23:22:00.335 Status: dzVents: Error (2.4.7): /home/pi/domoticz/dzVents/runtime/Domoticz.lua:163: attempt to perform arithmetic on local 'x' (a nil value)
2018-10-21 23:22:00.335 Status: dzVents: Info: ------ Finished weerbericht
Pushover settings are fine, I receive notifications from other scripts...
Hi Joep, the script is tested and works for the temp + hum + baro device. Can you please check if your device is of that type.
I will send you a PM with a script with some additional debug lines.
Re: How to get Text from sensor
Posted: Monday 22 October 2018 5:01
by misko903
waaren wrote:misko903 wrote: Sunday 21 October 2018 19:19
for me it works!!! the only thing is the accuracy - lenght of the temperatures - 10.39999961853°
Plus how can I send the notifications
only throug a specific service - for example gcm (not gmail)?
Please check the improved version
Code: Select all
return {
on = { timer = { "at 08:00"}},
execute = function(dz)
local myDevice = dz.devices(1103) -- change this to the ID of your device or the name in quotes
local toLog = true -- switch between true/false when you want/don't want an entry in logfile
local email = false -- switch between true/false when you want/don't want to be Emailed
local notify = true -- switch between true/false when you want/don't want a notification
local myNotificationTable = {dz.NSS_GOOGLE_CLOUD_MESSAGING, dz.NSS_PUSHOVER} -- table with one or more notification system. Can be one or more of
-- dz.NSS_GOOGLE_CLOUD_MESSAGING,
-- dz.NSS_HTTP,
-- dz.NSS_KODI,
-- dz.NSS_LOGITECH_MEDIASERVER,
-- dz.NSS_NMA,
-- dz.NSS_PROWL,
-- dz.NSS_PUSHALOT,
-- dz.NSS_PUSHBULLET,
-- dz.NSS_PUSHOVER,
-- dz.NSS_PUSHSAFER
local degree = '°'
local notifyString = "Today it will be " .. myDevice.forecastString ..
" (" .. myDevice.barometer .." hPa). The expected temperature will be " ..
dz.utils.round(myDevice.temperature,1) .. degree .. " and the humidity will feel as " .. myDevice.humidityStatus
if toLog then dz.log(notifyString:gsub(degree," degrees"),dz.LOG_INFO) end
if email then dz.email("Weather forecast",notifyString,"[email protected]") end
if notify then dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable ) end
end
}
Perfect

I will test it from the work. To change it to Monday till Friday (work days) should be a piece of cake also for me

("at 05:40 on mon,tue,wed,thu,fri")
There is "prediction: cloudy" part missing. How should the code part for it looks like?
Maybe you can help also here; my wife gets the notifications too. She is not waking every morning as me (baby). And I don't want to disturb her with my test messages.
How to send the messages to the specific user?
I will use the script parts also for gardening - the message about dry flower will be sent only to her.
Now I see that to do this in blockly is practically impossible. I am trying to do as much as possible in dzVents.
Greets from Slovakia!
Re: How to get Text from sensor
Posted: Monday 22 October 2018 9:14
by waaren
misko903 wrote: Monday 22 October 2018 5:01
Perfect

I will test it from the work. To change it to Monday till Friday (work days) should be a piece of cake also for me

("at 05:40 on mon,tue,wed,thu,fri")
That should work
There is "prediction: cloudy" part missing. How should the code part for it looks like?
there seem to be an inconsistency in domoticz wrt the to the behavior of this value.
For now I added the function fromBarometerForecastInfo to ensure a correct prediction string. (see new code)
How to send the messages to the specific user?
This is out of control for dzVents. In the script you can choose to which notification systems you want to send the information but you have to define in domoticz notification setup page who the addressee will be.
Code: Select all
return {
on = { timer = { "at 09:07"}},
execute = function(dz)
local myDevice = dz.devices(1103) -- change this to the ID of your device or the name in quotes
local toLog = true -- switch between true/false when you want/don't want an entry in logfile
local email = false -- switch between true/false when you want/don't want to be Emailed
local notify = true -- switch between true/false when you want/don't want a notification
local myNotificationTable = {dz.NSS_GOOGLE_CLOUD_MESSAGING, dz.NSS_PUSHOVER} -- table with one or more notification system. Can be one or more of
-- dz.NSS_GOOGLE_CLOUD_MESSAGING,
-- dz.NSS_HTTP,
-- dz.NSS_KODI,
-- dz.NSS_LOGITECH_MEDIASERVER,
-- dz.NSS_NMA,
-- dz.NSS_PROWL,
-- dz.NSS_PUSHALOT,
-- dz.NSS_PUSHBULLET,
-- dz.NSS_PUSHOVER,
-- dz.NSS_PUSHSAFER
local function fromBarometerForecastInfo(pressure) -- Return text
if pressure == nil then return nil -- Should not happen
elseif pressure < 966 then return "Thunderstorm"
elseif pressure < 993 then return "Cloudy / Rain"
elseif pressure < 1007 then return "Cloudy"
elseif pressure < 1013 then return "Unstable"
elseif pressure < 1033 then return "Stable"
end
return "Sunny"
end
local degree = '°'
local notifyString = "Today it will be " .. fromBarometerForecastInfo(myDevice.barometer) ..
" (" .. myDevice.barometer .." hPa). The expected temperature will be " ..
dz.utils.round(myDevice.temperature,1) .. degree .. " and the humidity will feel as " .. myDevice.humidityStatus
if toLog then dz.log(notifyString:gsub(degree," degrees"),dz.LOG_INFO) end
if email then dz.email("Weather forecast",notifyString,"[email protected]") end
if notify then dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable ) end
end
}
Re: How to get Text from sensor
Posted: Monday 22 October 2018 18:23
by Joep123
waaren wrote: Sunday 21 October 2018 23:54
Hi Joep, the script is tested and works for the temp + hum + baro device. Can you please check if your device is of that type.
I will send you a PM with a script with some additional debug lines.
Hi waaren, the improved version of Sunday 21 October 2018 21:14 works perfect, better than the newest version because of the pressure is exactly 1033 here now. The newest version results in "Sunny" but should be "Partly Cloudy".
I used a text sensor

Re: How to get Text from sensor
Posted: Monday 22 October 2018 21:43
by misko903
I was trying to find the option to send the message to specified user in Domoticz. Nothing found

not in settings - messaging, not in mobile devices, not in users.
Maybe it can be added as a feature in next Dz update?
Your script test will run in the morning, looking forward to it
M
Re: How to get Text from sensor
Posted: Friday 26 October 2018 21:19
by misko903
A battery low message is keeping rewriting me the weather message. I need to replace batt first. After I will write the result (still did not found setting of sending message to specific user)
Re: How to get Text from sensor
Posted: Monday 29 October 2018 7:47
by misko903
It works

Thank you waaren, great!!!
