Set user variable from pythonscript

Python and python framework

Moderator: leecollings

Post Reply
manul
Posts: 1
Joined: Saturday 21 October 2017 16:59
Target OS: -
Domoticz version:
Contact:

Set user variable from pythonscript

Post by manul »

I would like to update a uservariable, I thought this should work but it doesn't
DE.Command('Variable:user_var' , str(5))

To update an sensor I use this and it works well
DE.Command('lamp', "Off")
soikka
Posts: 1
Joined: Sunday 05 November 2017 14:40
Target OS: Linux
Domoticz version:
Contact:

Re: Set user variable from pythonscript

Post by soikka »

Same results, user variables are not working for me neither.

I have built Domoticz from development branch, version 3.8693, hopefully this is new enough. It seems that there is no support for user variables yet, actually most of the stuff which is working in Lua seems missing.

I managed to get user variables working with quick&dirty hack, simply trying to copy functionality from Lua. Finally managed to get it somehow working but unfortunately hit blocker with some mutex, basically needed dirty hack to go around. I really do not understand how m_uservariablesMutex is supposed to be working down there (in EventSystem.cpp). Anybody developing full Python support - or knows where are we here?

My approach, just to give you an idea, hopefully did not miss anything important:

1. Added user variable handler to
CEventSystem::ScheduleEvent(std::string deviceName, const std::string &Action, const std::string &eventName)

Code: Select all

...
	}
	else if ((deviceName.find("Variable:") == 0))
	{
		isVariable = true;
		deviceName = deviceName.substr(9);
	}
...
	  if (isVariable) {
	        std::vector<std::string> variableID = result[0];
		std::vector<std::vector<std::string> > result2;
		std::vector<std::string> valueAndType;
		std::string updateResult;

		result2 = m_sql.safe_query("SELECT Name, ValueType FROM UserVariables WHERE (ID == '%q')", variableID[0].c_str());
		if (result2.size() > 0) {
		         valueAndType = result2[0];
		         updateResult = m_sql.UpdateUserVariable(variableID[0], valueAndType[0], valueAndType[1], Action, false);
		         if (updateResult != "OK") {
			         _log.Log(LOG_ERROR, "Schedule
			         Event: Error variable %s: %s", valueAndType[0].c_str(), updateResult.c_str());
			 }
		}
		return true;
	  } else {
...
Here is the difference: https://pastebin.com/Kdz2kjDD

2. I needed to comment away in CEventSystem::UpdateUserVariable()

Code: Select all

// Blocked here, need to comment away, don't yet understand why...
// boost::unique_lock<boost::shared_mutex> uservariablesMutexLock(m_uservariablesMutex); 
in CEventSystem::UpdateUserVariable(). Otherwise code was blocked in this call.

I need more time to investigate...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest