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

Offline rafale77

  • Hero Member
  • *****
  • Posts: 713
  • Karma: +35/-20
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.
127 zwave nodes, 8 zigbee nodes, 256 devices, 17 apps, 128 scenes on a Vera Plus linked with Echo and HomeKit through bridges

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9741
  • Karma: +737/-136
    • RTS Services Plugins
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: 5234
  • Karma: +226/-67
  • "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.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Hero Member
  • *****
  • Posts: 713
  • Karma: +35/-20
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.
127 zwave nodes, 8 zigbee nodes, 256 devices, 17 apps, 128 scenes on a Vera Plus linked with Echo and HomeKit through bridges