How to change a variable through Luup?

I’m using this geat plugin to control the engine heater of my car. Now I would like to set the variable gc_StartDelta depending on the outside temperature. How do I change the variable gc_StartDelta by Luup code (Lua)? I have tried the code below without success.

luup.variable_set("urn:srs-com:serviceId:GCalIII", "gc_StartDelta", -100, 184)
luup.variable_set("urn:srs-com:serviceId:GCal3", "gc_StartDelta", -100, 184)

Edit:
It seems like the second code (GCal3) only adds new variables to the device (now I have three variables named “gc_StartDelta”). I have no idea how to get rid of those copies…

The first code (GCalIII) makes the change in the correct variable but the change doesn’t have any effect on the events start time until I do a luup reload. Any way to get the change to take effect without a reload?

Variables are typically used to save the state of a device. Changing them just invalidates the devices internal state. (That is why reloading works.)

The only (guaranteed) way to make a device react to a change is to call one of it’s supported a actions.

You can find the list of supported actions from the Advanced tab of the Scene editor or the Advanced Tab of the PLEG actions editor.

[quote=“mht, post:1, topic:189420”]I’m using this geat plugin to control the engine heater of my car. Now I would like to set the variable gc_StartDelta depending on the outside temperature. How do I change the variable gc_StartDelta by Luup code (Lua)? I have tried the code below without success.

luup.variable_set("urn:srs-com:serviceId:GCalIII", "gc_StartDelta", -100, 184)
luup.variable_set("urn:srs-com:serviceId:GCal3", "gc_StartDelta", -100, 184)

Edit:
It seems like the second code (GCal3) only adds new variables to the device (now I have three variables named “gc_StartDelta”). I have no idea how to get rid of those copies…

The first code (GCalIII) makes the change in the correct variable but the change doesn’t have any effect on the events start time until I do a luup reload. Any way to get the change to take effect without a reload?[/quote]

In earlier releases of the plugin some variables were only updated when the plugin was reloaded. Why ? I cannot remember …

V 1.4 was released a couple of days ago, and one of the changes I made was for changes to variables to refresh whenever the calendar was read (i.e. at the start and end of events, whenever the “check” button is pressed and whenever an event is added to the calendar via the plugin.

Note that due to the strange behavior of the Vera interface - updates may require an “F5” or even closing and reopening the browser to show up correctly (nothing I can do about that).

The correct form of the code is:

luup.variable_set("urn:srs-com:serviceId:GCalIII", "gc_StartDelta", -100, 184)

The other form adds variables that are in effect “unknown” to the plugin code (they live somewhere in Vera associated to the plugin but that’s it). As far as I know, the only way to get rid of them is to uninstall the plugin and reinstall it.

Note that setting the variable gc_StartDelta affects all events. So you might want to consider creating an event in the calendar (via the plugin) with the calculated earlier start time and use that to start your car ? Maybe a scene that runs at (say) midnight, looks to see when the “go to work” event is scheduled (by consulting gc_jsonEvents), calculates a “start car” event with the appropriate ‘earliness’ and has the plugin create it for you in the calendar. Then use a simple scene that triggers on the “start car” event to start the car ?

Here:s some sample code you could base the reading of the coming events:


.......

local function getjsonEvents() -- this is really some sample code and useful for debugging
  local jsonEvents = luup.variable_get(GCAL_SID, "gc_jsonEvents",lul_device)

  if (jsonEvents == "[]") then -- equivalent of a nul so don't try
    return false
  end

  local json = require("json")  
  local eventList =json.decode(jsonEvents)
  package.loaded.json = nil

  local numberEvents = table.getn(eventList)
  local startevent, startDate, startTime, endevent, endTime, eventname, event
  
  for i = 1,numberEvents do
    startevent = eventList[i].eventStart
    --startevent = os.date("%Y-%m-%dT%H:%M:%S",startevent)
    startDate = os.date("%Y-%m-%d", startevent)
    startTime = os.date("%H:%M:%S", startevent)
    endevent = eventList[i].eventEnd
    endTime = os.date("%H:%M:%S", endevent)
    eventname = eventList[i].eventName
    event = "On " .. startDate .. " event " .. eventname .. " will start at " .. startTime .. " and end at " .. endTime
    print ("Event " .. i .. ": " .. event)
  end
  return true
end

Thank you for your thorough answer!
I had a couple of questions besides the one in my original post. Now I have got them answered too!