Author Topic: Scene Last run time as a variable  (Read 335 times)

Offline rafale77

  • Hero Member
  • *****
  • Posts: 1103
  • Karma: +52/-21
Scene Last run time as a variable
« on: August 26, 2017, 01:34:34 pm »
Anyone knows how I could get the last run time of a scene? I am trying to automate around it. I could create a virtual sensor and use the last trip variable but it seems cumbersome.
Would be great if I could extract it. I am sure it is available somewhere since it is displayed on the UI but can't find a way to extract.
openLuup (93 devices, 122 scenes, 20 apps) controlling HomeAss + VeraPlus (133 zwave nodes, 8 Zigbee nodes, 203 devices, 34 scenes , 3 apps) Bridged to Homekit and Alexa

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10059
  • Karma: +759/-141
Re: Scene Last run time as a variable
« Reply #1 on: August 26, 2017, 01:58:01 pm »
You can do it by parsing the user_data object.
The UI grabs the entire user data object (contains all devices, all scenes, ...)

A typical scene object (json format) looks like:
{
    "name": "Heat  to 66 at 7am SS",
    "room": "11",
    "triggers_operator": "OR",
    "groups": [
   { "delay": 0, "actions": [
       { "device": "13", "service": "urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "action": "SetModeTarget", "arguments": [ { "name": "NewModeTarget", "value": "HeatOn" } ] },
       { "device": "13", "service": "urn:upnp-org:serviceId:TemperatureSetpoint1", "action": "SetCurrentSetpoint", "arguments": [ { "name": "NewCurrentSetpoint", "value": "66.0" } ] } ] } ],
    "triggers": [ ],
    "timers": [
   { "id": "1", "name": "", "enabled": 1, "type": 2, "days_of_week": "6,7", "time": "7:30:0", "last_run": 1499610600, "next_run": 1500129000 } ],
    "users": "",
    "paused": 0,
    "modeStatus": "1,3",
    "id": 21,
    "Timestamp": 1493601511,
    "last_run": 1499610600
}
A lot of the data that is available in the user_data object is NOT available from MCV LUA extensions.
See: http://wiki.micasaverde.com/index.php/Luup_Requests#user_data  to access the user_data object

I would take a different route ... I would add some LUA to your scene that stores the time in a Global Variable in LUA or as a device parameter on some Vera Device Object. Then you can access it at a later time.

Offline akbooer

  • Master Member
  • *******
  • Posts: 5869
  • Karma: +249/-69
  • "Less is more"
Re: Scene Last run time as a variable
« Reply #2 on: August 26, 2017, 03:29:28 pm »
In fact, there's no need to grab the whole user_data structure... a simple HTTP request can return just a specific scene's code.  See http://wiki.micasaverde.com/index.php/Luup_Requests#scene

However, I do agree that this is probably not the best way to approach it if you are able to add code to the scene instead.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Hero Member
  • *****
  • Posts: 1103
  • Karma: +52/-21
Re: Scene Last run time as a variable
« Reply #3 on: August 26, 2017, 04:11:55 pm »
Thank you both. Didn't think about doing a Luup request. Will look into it.
openLuup (93 devices, 122 scenes, 20 apps) controlling HomeAss + VeraPlus (133 zwave nodes, 8 Zigbee nodes, 203 devices, 34 scenes , 3 apps) Bridged to Homekit and Alexa