Author Topic: Sonos Say last time a sensor as been trip  (Read 358 times)

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 138
  • Karma: +2/-0
Sonos Say last time a sensor as been trip
« on: July 20, 2017, 06:47:41 pm »
Sonos cannot says last time a sensor as been trip, instead it give a billion number.
How can i convert that number to time it as been trip?


Code: [Select]
local SONOS_ID = 194
local SONOS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SONOS_ZONES="Cuisine"

local time = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","LastTrip", 183)

local greeting="personne ,es venu ici depuis le,"



luup.call_action(SONOS_SID, "Say",
                 {Text= " Le syst?me de surveillance vous di,  "..greeting .. time , Language="fr-CA", GroupZones=SONOS_ZONES,
                  Volume=volume, SameVolumeForAll="true"},
                 SONOS_ID)

Offline BOFH

  • Sr. Hero Member
  • ******
  • Posts: 2410
  • Karma: +112/-139
Re: Sonos Say last time a sensor as been trip
« Reply #1 on: July 20, 2017, 10:12:31 pm »
The time value you are getting returned is in Unix style seconds since a specific date. You have to feed it to the os.time function and specify the format you want it as. See http://www.lua.org/pil/22.1.html for more info on that.
Vera3 UI5 UI7 Edge Plus
Trane TZEMT400AB32 | Schlage BE369 FE599 | GE 45601 45602 45603 45604 45606 45609 45631 | Intermatic HA01C HA03C HA05C HA07C CA600 CA3000 | Aeon DSC06106 | Telguard GDC1 | Foscam FI8910W FI8905W FI9821W | D-Link 930L | Wanscam JW0011 | ZModo ZPIBH13W

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 138
  • Karma: +2/-0
Re: Sonos Say last time a sensor as been trip
« Reply #2 on: July 21, 2017, 09:13:16 am »
It look like a good reference but, i m not very good in programming + english reading (mean more difficult).
i just want Sonos to say something like:  March 25 2017 at 22:17. (last time sensor been trip)
Thanks if somebody can help with that.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 550
  • Karma: +30/-2
Re: Sonos Say last time a sensor as been trip
« Reply #3 on: July 21, 2017, 04:31:48 pm »
Code: [Select]
...
local time = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","LastTrip", 183)
local timeString = os.date(" %B %d %Y at %X", time)

local greeting="personne ,es venu ici depuis le,"

luup.call_action(SONOS_SID, "Say",
                 {Text= " Le syst?me de surveillance vous di,  "..greeting .. timeString, Language="fr-CA", GroupZones=SONOS_ZONES,
                  Volume=volume, SameVolumeForAll="true"},
                 SONOS_ID)

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 138
  • Karma: +2/-0
Re: Sonos Say last time a sensor as been trip
« Reply #4 on: July 21, 2017, 10:05:25 pm »
It Works !!!
Something weird it say the number in french and say the month in english...
But it is ok for now.

Thank you very much Jswim788

Offline jswim788

  • Hero Member
  • *****
  • Posts: 550
  • Karma: +30/-2
Re: Sonos Say last time a sensor as been trip
« Reply #5 on: July 21, 2017, 11:46:07 pm »
Code: [Select]
...
local time = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","LastTrip", 183)
local timeString = os.date(" %d %Y a %X", time)
local month = tonumber(os.date("%m",time))
local frMonth = { "janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet","aout","septembre","octobre","novembre","decembre"}

timeString = frMonth[month] .. timeString

local greeting="personne ,es venu ici depuis le, "

luup.call_action(SONOS_SID, "Say",
                 {Text= " Le syst?me de surveillance vous di,  "..greeting .. timeString, Language="fr-CA", GroupZones=SONOS_ZONES,
                  Volume=volume, SameVolumeForAll="true"},
                 SONOS_ID)
I don't know how to get the special characters into the text, but maybe the above will work?  I bet @amg0 can do better for translation...

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 138
  • Karma: +2/-0
Re: Sonos Say last time a sensor as been trip
« Reply #6 on: July 22, 2017, 10:20:44 pm »
Thanks again    jswim788 .