How to get Text from sensor Topic is solved

Post Reply
misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

How to get Text from sensor

Post by misko903 » 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.

Image

How to do it? Is there any spec value, or should I create a virtual switch, or...?

Thank you,
Michal, SVK

User avatar
waaren
Posts: 1221
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to get Text from sensor

Post by waaren » Saturday 20 October 2018 16:21

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.

Image

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)
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: How to get Text from sensor

Post by misko903 » Saturday 20 October 2018 20:41

This:

Temp + Humidity + Baro
THB1 - BTHR918, BTHGN129

User avatar
waaren
Posts: 1221
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to get Text from sensor

Post by waaren » Sunday 21 October 2018 1:13

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 
} 
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Joep123
Posts: 29
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: How to get Text from sensor

Post by Joep123 » Sunday 21 October 2018 11:14

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.

misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: How to get Text from sensor

Post by misko903 » Sunday 21 October 2018 19:19

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)?

User avatar
waaren
Posts: 1221
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to get Text from sensor

Post by waaren » Sunday 21 October 2018 21:14

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,"emailAdres@provider.com") end
        if notify then dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable ) end
    end 
} 
Last edited by waaren on Sunday 21 October 2018 21:30, edited 2 times in total.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
waaren
Posts: 1221
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to get Text from sensor

Post by waaren » Sunday 21 October 2018 21:20

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Joep123
Posts: 29
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: How to get Text from sensor

Post by Joep123 » 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...

User avatar
waaren
Posts: 1221
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to get Text from sensor

Post by waaren » Sunday 21 October 2018 23:54

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: How to get Text from sensor

Post by misko903 » Monday 22 October 2018 5:01

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,"emailAdres@provider.com") 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!

User avatar
waaren
Posts: 1221
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to get Text from sensor

Post by waaren » Monday 22 October 2018 9:14

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,"emailAdres@provider.com") end
        if notify then dz.notify("Weather forecast", notifyString, dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable ) end
    end 
} 
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Joep123
Posts: 29
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: How to get Text from sensor

Post by Joep123 » Monday 22 October 2018 18:23

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 :oops: :oops:

misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: How to get Text from sensor

Post by misko903 » Monday 22 October 2018 21:43

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

misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: How to get Text from sensor

Post by misko903 » Friday 26 October 2018 21:19

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)

misko903
Posts: 46
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: How to get Text from sensor

Post by misko903 » Monday 29 October 2018 8:47

It works :)
Thank you waaren, great!!!Image

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests