Math operators and Blocking

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Sunday 12 November 2017 17:34

But actually you can't use user variables or devices....

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Wednesday 06 December 2017 14:53

Mesomorf wrote:
Friday 10 November 2017 7:21
ebretteville wrote:
Saturday 21 October 2017 15:05
I think I got it working.
Please! Can you PM me what files you moddified in Domoticz to get open up math? I tried myself and found some references in the www folder but without success.
Thx?! ;-)

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Wednesday 06 December 2017 19:08

With loops, to be placed at /home/pi/domoticz/www/ in a file named eventsframe.html

Code: Select all

<html>
  <head>
    <meta charset="utf-8">
    <script type="text/javascript" src="js/blockly_compressed.js"></script>
    <script type="text/javascript" src="js/blocks_compressed.js"></script>
    <script type="text/javascript" src="js/en_compressed.js"></script>
    <script type="text/javascript" src="js/jquery-1.12.0.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/bootbox.min.js"></script> 
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="js/noty/jquery.noty.js"></script>
    <script type="text/javascript" src="js/noty/layouts/top.js"></script>
    <script type="text/javascript" src="js/noty/layouts/topRight.js"></script>
    <script type="text/javascript" src="js/noty/themes/default.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/domoticz.js"></script>
    <script type="text/javascript" src="js/domoticzblocks_messages_en.js"></script>	
    <script type="text/javascript" src="js/domoticzblocks.js"></script>
	<script src="js/i18next-1.8.0.min.js"></script>
	<script type="text/javascript" src="js/bootbox.min.js"></script>
	<script type="text/javascript" src="js/ace/ace.js"></script>
	<script type="text/javascript" src="js/ace/ext-language_tools.js"></script>
	<link rel="stylesheet" href="css/bootstrap.css">
    <link href="css/bootstrap-responsive.css" rel="stylesheet" media="screen">
    <link type="text/css" rel="stylesheet" href="css/ui-darkness/jquery-ui.min.css" />
    <link type="text/css" rel="stylesheet" href="css/style.css" />	
	    
    <style>
      html, body {
        background-color: transparent;
        background: transparent;
        margin: 0;
        padding: 0;
        overflow: hidden;
      }
      .blocklySvg {
        height:100%;
        width: 100%; 
      }
      .blocklyTreeRow {
        color:black;
      }
      #saveTable
      { border-spacing: 8px;
    	padding:2px 2px 2px 2px;
      }
		#aceDiv { 
			position: relative;
			height: 700px;
			}
    </style>
    <script>
	  var editor;
	  
      function init() {
      	Blockly.inject(document.getElementById('blocklyDiv'),
        {
			path: './',
			toolbox: document.getElementById('toolbox'),
			zoom: {
				controls: true,
				wheel: true,
				startScale: 1.0,
				maxScale: 3,
				minScale: 0.3,
				scaleSpeed: 1.2
				},
			trashcan: true
		});
        window.parent.blocklyLoaded(Blockly);

		editor = ace.edit("aceDiv");
		editor.setTheme("ace/theme/xcode");
		editor.setOptions({enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: true});
        load_blocks();
      }
      
      function opSymbol(operand) {
	     switch(operand)
		{
		case 'EQ':
		  operand = ' == ';
		  break;
		case 'NEQ':
		  operand = ' ~= ';
		  break;
		case 'LT':
		  operand = ' < ';
		  break;
		case 'GT':
		  operand = ' > ';
		  break;
		case 'LTE':
		  operand = ' <= ';
		  break;
		case 'GTE':
		  operand = ' >= ';
		  break;
		default:
		} 
		return operand;		     
      }
      
      function parseXml(xml) {
      
        if ($(xml).children().length > 1) {
		  	return "err:Please make sure there is only a single block structure";
		}
		var firstBlockType = $(xml).find("block").first().attr("type");
	    if (firstBlockType.indexOf("domoticzcontrols_if") == -1) {
	  		return "err:Please start with a control block";
	    }
	    var elseIfCount = 0;
	    if (firstBlockType == "domoticzcontrols_ifelseif")
	    {
		    var elseIfString = $(xml).find("mutation:first").attr("elseif");
		    elseIfCount = parseInt(elseIfString);
	    }
	    elseIfCount++;
	    
	    var json = {};
	    json.eventlogic = []
	    
	    for (var i=0;i<elseIfCount;i++)
	    { 
	    	conditionActionPair = parseXmlBlocks(xml,i);
		    var oneevent = {};
		    oneevent.conditions = conditionActionPair[0].toString();
		    oneevent.actions = conditionActionPair[1].toString();
		    json.eventlogic.push(oneevent);
 		}
		
		return json;
		
      }
      
      function parseXmlBlocks(xml,pairId) {
      	var boolString = "";
     
		function GetValueText(value, variableType) {
			if (variableType.indexOf("switchvariables") >= 0) {
				var fieldA = $(value).find("field")[0];
				return "device["+$(fieldA).text()+"]";
			}
			else if (variableType.indexOf("uservariables") >= 0) {
				var fieldA = $(value).find("field")[0];
				return "variable["+$(fieldA).text()+"]";
			}
			else if (variableType == "temperaturevariables") {
				var fieldA = $(value).find("field")[0];
				return "temperaturedevice["+$(fieldA).text()+"]";
			}
			else if (variableType == "humidityvariables") {
				var fieldA = $(value).find("field")[0];
				return "humiditydevice["+$(fieldA).text()+"]";
			}
			else if (variableType == "dewpointvariables") {
				var fieldA = $(value).find("field")[0];
				return "dewpointdevice["+$(fieldA).text()+"]";
			}
			else if (variableType == "barometervariables") {
				var fieldA = $(value).find("field")[0];
				return "barometerdevice["+$(fieldA).text()+"]";
			}
			else if (variableType.indexOf("utilityvariables") >= 0) {
				var fieldA = $(value).find("field")[0];
				return "utilitydevice["+$(fieldA).text()+"]";
			}
			else if (variableType.indexOf("weathervariables") >= 0) {
				var fieldA = $(value).find("field")[0];
				return "weatherdevice["+$(fieldA).text()+"]";
			}
			else if (variableType.indexOf("zwavealarms") >= 0) {
				var fieldA = $(value).find("field")[0];
				return "zwavealarms["+$(fieldA).text()+"]";
			}
			else {
				var fieldB = $(value).find("field")[0];
				if ($(fieldB).attr("name") == "State") {
					return '"'+$(fieldB).text()+'"'; 
				}
				else if ($(fieldB).attr("name") == "TEXT") {
					return '"'+$(fieldB).text()+'"'; 
				}
				else if ($(fieldB).attr("name") == "NUM") {
					return $(fieldB).text();
				}
				return "unknown comparevariable "+variableType;
			}
		}
     
		function parseLogicCompare(thisBlock){
			var locOperand = opSymbol($($(thisBlock).children("field:first")).text());
			var valueA = $(thisBlock).children("value[name='A']")[0];
			var variableTypeA = $(valueA).children("block:first").attr("type");
			var valueB = $(thisBlock).children("value[name='B']")[0];
			var variableTypeB = $(valueB).children("block:first").attr("type");
			var varTextA=GetValueText(valueA,variableTypeA);
			var varTextB=GetValueText(valueB,variableTypeB);

			var compareString = varTextA;
			compareString += locOperand;
			compareString += varTextB; 
			return compareString;
		}
		
		function parseLogicTimeOfDay(thisBlock) {
				var compareString = "";
				var locOperand = opSymbol($($(thisBlock).children("field:first")).text());
				var valueTime = $(thisBlock).children("value[name='Time']")[0];
				var timeBlock = $(valueTime).children("block:first");
				if (timeBlock.attr("type")=="logic_timevalue") {	
					var valueA = $(timeBlock).children("field[name='TEXT']")[0];			
					var hours=parseInt($(valueA).text().substr(0,2));
					var minutes=parseInt($(valueA).text().substr(3,2));
					var totalminutes=(hours*60)+minutes;
					compareString = 'timeofday '+locOperand+' '+totalminutes;
				}
				else if (timeBlock.attr("type")=="logic_sunrisesunset") {
					var valueA = $(timeBlock).children("field[name='SunriseSunset']")[0];
					compareString = 'timeofday '+locOperand+' @'+$(valueA).text(); 
				}
				else if (timeBlock.attr("type").indexOf("uservariables") >= 0) {
					var fieldA = $(timeBlock).find("field[name='Variable']")[0];
					var valueA = "variable["+$(fieldA).text()+"]";         
					compareString = 'timeofday '+locOperand+' tonumber(string.sub('+valueA+',1,2))*60+tonumber(string.sub('+valueA+',4,5))';
				}
				return compareString;	
		}
		
		function parseLogicWeekday(thisBlock) {
				var locOperand = opSymbol($($(thisBlock).children("field:first")).text());
				var valueA = $(thisBlock).children("field[name='Weekday']")[0];
				var compareString = 'weekday '+locOperand+' '+$(valueA).text(); 
			  	return compareString;
		}		

		function parseSecurityStatus(thisBlock) {
				var locOperand = opSymbol($($(thisBlock).children("field:first")).text());
				var valueA = $(thisBlock).children("field[name='Status']")[0];
				var compareString = 'securitystatus '+locOperand+' '+$(valueA).text(); 
			  	return compareString;
		}
		
		function parseValueBlock(thisBlock,locOperand,Sequence) {
			var firstBlock = $(thisBlock).children("block:first");
			if (firstBlock.attr("type")=="logic_compare") {
				var conditionstring = parseLogicCompare(firstBlock);
			  	return conditionstring;
			}
			else if (firstBlock.attr("type")=="logic_weekday") {
				var conditionstring = parseLogicWeekday(firstBlock);
				return conditionstring;
			}
			else if (firstBlock.attr("type")=="logic_timeofday") {
				var conditionstring = parseLogicTimeOfDay(firstBlock);
				return conditionstring;
			}
			else if (firstBlock.attr("type")=="logic_operation") {
				var conditionstring = parseLogicOperation(firstBlock);
				return conditionstring;
			}
			else if (firstBlock.attr("type")=="security_status") {
      			var conditionstring = parseSecurityStatus(firstBlock);
      			return conditionstring;
      		} 
		}
		
    	function parseLogicOperation(thisBlock){
    		var locOperand = ' '+$($(thisBlock).children("field:first")).text().toLowerCase()+' ';
			var valueA = $(thisBlock).children("value[name='A']")[0];
			var valueB = $(thisBlock).children("value[name='B']")[0];
			var conditionA = parseValueBlock(valueA,locOperand,"A");
			var conditionB = parseValueBlock(valueB,locOperand,"B");
			var conditionstring = "("+conditionA+" "+locOperand+" "+conditionB+")";
			return conditionstring; 
		}
	    
	    var ifBlock = $($(xml).find("value[name='IF"+pairId+"']")[0]).children('block:first');

      	if (ifBlock.attr("type")=="logic_compare") {
      		// just the one compare, easy
      		var compareString = parseLogicCompare(ifBlock);
      		boolString += compareString;
      	}

      	else if (ifBlock.attr("type")=="logic_operation") {
      		// nested logic operation, drill down
      		var compareString = parseLogicOperation(ifBlock);
       		boolString += compareString;
    
      	}
      	else if (ifBlock.attr("type")=="logic_timeofday") {
      		// nested logic operation, drill down
      		var compareString = parseLogicTimeOfDay(ifBlock);
      		boolString += compareString;
      	}
      	else if (ifBlock.attr("type")=="logic_weekday") {
      		// nested logic operation, drill down
      		var compareString = parseLogicWeekday(ifBlock);
      		boolString += compareString;
      	}
      	else if (ifBlock.attr("type")=="security_status") {
      		// nested logic operation, drill down
      		var compareString = parseSecurityStatus(ifBlock);
      		boolString += compareString;
      	}      	
      	var setArray = [];
      	var doBlock = $($(xml).find("statement[name='DO"+pairId+"']")[0]);
 	      $(doBlock).find('block').each (function(){ 
			if ($(this).attr('type') == 'logic_set') {
		   		var valueA = $(this).find("value[name='A']")[0];
	        	var fieldA = $(valueA).find("field")[0];
	        	var blockA = $(valueA).children("block:first");
				if (blockA.attr("type").indexOf("uservariables") >= 0) { 
					var setString = "commandArray[Variable:"+$(fieldA).text()+"]";
					var valueB = $(this).find("value[name='B']")[0];
					var fieldB = $(valueB).find("field")[0];
					var blockB = $(valueB).children("block:first");
					var variableTypeB = $(valueB).children("block:first").attr("type");
					var dtext=GetValueText(valueB,variableTypeB);
					setString += '='+dtext+''; 
					setArray.push(setString);
								
				}
				else {
					var setString = "commandArray["+$(fieldA).text()+"]";
					var valueB = $(this).find("value[name='B']")[0];
					var fieldB = $(valueB).find("field")[0];
					var blockB = $(valueB).children("block:first");
					if ((blockB.attr("type")=="logic_states") && ($(fieldB).attr("name") == "State")) {
						setString += '="'+$(fieldB).text()+'"'; 
						setArray.push(setString);
					}
					else if ((blockB.attr("type")=="logic_setlevel") && ($(fieldB).attr("name") == "NUM")) {
						setString += '="Set Level '+$(fieldB).text()+'"'; 
						setArray.push(setString);
					}
					else {
						//not handled
						//alert('A Type: ' + blockA.attr("type") + ', B Type: ' + blockB.attr("type") + ', FieldB: ' + $(fieldB).attr("name"));
					}
					//else if ((blockB.attr("type")=="math_number") && ($(fieldB).attr("name") == "NUM")) {
					//	setString += '="'+$(fieldB).text()+'"'; 
					//	setArray.push(setString);
					//}
				}
		    }
	      	else if ($(this).attr('type') == 'logic_setafter') {
		   		var valueA = $(this).find("value[name='A']")[0];
	        	var fieldA = $(valueA).find("field")[0];
	        	var valueC = $(this).find("value[name='C']")[0];
	        	var fieldC = $(valueC).find("field")[0];
	        	var blockA = $(valueA).children("block:first");
		        var setString = "commandArray["+$(fieldA).text()+"]";
	        	var valueB = $(this).find("value[name='B']")[0];
	        	var fieldB = $(valueB).find("field")[0];
	        	var blockB = $(valueB).children("block:first");
	        	
	        	var blockBType=blockB.attr("type");
	        	var fieldBName=$(fieldB).attr("name");
		        if ((blockBType=="logic_states") && (fieldBName == "State")) {
	        		setString += '="'+$(fieldB).text()+' AFTER '+ $(fieldC).text()+'"'; 
	        		setArray.push(setString);
	        	}        	
	        	else if ((blockBType=="logic_setlevel") && (fieldBName == "NUM")) {
	        		setString += '="Set Level '+$(fieldB).text()+' AFTER '+ $(fieldC).text()+'"'; 
	        		setArray.push(setString);
	        	}
		        else if ((blockBType=="math_number") && (fieldBName == "NUM")) {
					if (blockA.attr("type").indexOf("uservariables") >= 0) { 
						var setString = "commandArray[Variable:"+$(fieldA).text()+"]";
						var valueB = $(this).find("value[name='B']")[0];
						var fieldB = $(valueB).find("field")[0];
						var blockB = $(valueB).children("block:first");
						setString += '="'+$(fieldB).text()+''; 
						setString += ' AFTER '+ $(fieldC).text()+'"'; 
						setArray.push(setString);
					}
	        	}
		        else if ((blockBType=="text") && (fieldBName == "TEXT")) {
					if (blockA.attr("type").indexOf("uservariables") >= 0) { 
						var setString = "commandArray[Variable:"+$(fieldA).text()+"]";
						var valueB = $(this).find("value[name='B']")[0];
						var fieldB = $(valueB).find("field")[0];
						var blockB = $(valueB).children("block:first");
						setString += '="'+$(fieldB).text()+'"'; 
						setString += ' AFTER '+ $(fieldC).text()+'"'; 
						setArray.push(setString);
					}
	        	}
		    }
	      	else if ($(this).attr('type') == 'logic_setdelayed') {
		   		var valueA = $(this).find("value[name='A']")[0];
	        	var fieldA = $(valueA).find("field")[0];
	        	var valueC = $(this).find("value[name='C']")[0];
	        	var fieldC = $(valueC).find("field")[0];
	        	var blockA = $(valueA).children("block:first");
		        var setString = "commandArray["+$(fieldA).text()+"]";
	        	var valueB = $(this).find("value[name='B']")[0];
	        	var fieldB = $(valueB).find("field")[0];
	        	var blockB = $(valueB).children("block:first");
		        if ((blockB.attr("type")=="logic_states") && ($(fieldB).attr("name") == "State")) {
	        		setString += '="'+$(fieldB).text()+' FOR '+ $(fieldC).text()+'"'; 
	        		setArray.push(setString);
	        	}        	
	        	else if ((blockB.attr("type")=="logic_setlevel") && ($(fieldB).attr("name") == "NUM")) {
	        		setString += '="Set Level '+$(fieldB).text()+' FOR '+ $(fieldC).text()+'"'; 
	        		setArray.push(setString);
	        	}	        	

		    }
	      	else if ($(this).attr('type') == 'logic_setrandom') {
		   		var valueA = $(this).find("value[name='A']")[0];
	        	var fieldA = $(valueA).find("field")[0];
	        	var valueB = $(this).find("value[name='B']")[0];
	        	var fieldB = $(valueB).find("field")[0];
	        	var valueC = $(this).find("value[name='C']")[0];
	        	var fieldC = $(valueC).find("field")[0];
	        	var blockA = $(valueA).children("block:first");
		        var setString = "commandArray["+$(fieldA).text()+"]";
	        	var blockB = $(valueB).children("block:first");
		        if ((blockB.attr("type")=="logic_states") && ($(fieldB).attr("name") == "State")) {	        	
	        		setString += '="'+$(fieldB).text()+' RANDOM '+ $(fieldC).text()+'"'; 
	        		setArray.push(setString);
	        	}
		       	else if ((blockB.attr("type")=="logic_setlevel") && ($(fieldB).attr("name") == "NUM")) {
	        		setString += '="Set Level '+$(fieldB).text()+' RANDOM '+ $(fieldC).text()+'"'; 
	        		setArray.push(setString);
	        	}        	
	 	    }
		    else if ($(this).attr('type') == 'send_notification') {
		    	var subjectBlock = $(this).find("value[name='notificationTextSubject']")[0];
		    	var bodyBlock = $(this).find("value[name='notificationTextBody']")[0];
		    	var notificationBlock = $(this).children("field[name='notificationPriority']")[0];
			var soundBlock = $(this).children("field[name='notificationSound']")[0];
			var subsystemBlock = $(this).children("field[name='notificationSubsystem']")[0];
		    	var sFieldText = $(subjectBlock).find("field[name='TEXT']")[0];

			var sTT=GetValueText(subjectBlock,$(subjectBlock).children("block:first").attr("type")).replace(/\,/g, ' ');
			var bTT=GetValueText(bodyBlock,$(bodyBlock).children("block:first").attr("type")).replace(/\,/g, ' ');
				
		    	var pTT=$(notificationBlock).text();
			var aTT=$(soundBlock).text();
			var subTT=$(subsystemBlock).text();
		    	// message separator here cannot be # like in scripts, changed to $..
		    	// also removed commas as we need to separate commandArray later.
	        	var setString = 'commandArray["SendNotification"]="'+sTT+'$'+bTT+'$'+pTT+'$'+aTT+'$'+subTT+'"';
	        	setArray.push(setString);		      	
		    }
		    else if ($(this).attr('type') == 'send_email') {
				var subjectBlock = $(this).children("field[name='TextSubject']")[0];
				var bodyBlock = $(this).children("field[name='TextBody']")[0];
				var toBlock = $(this).children("field[name='TextTo']")[0];
				var sSubject = $(subjectBlock).text().replace(/\,/g, ' ');
		    	var sBody = $(bodyBlock).text().replace(/\,/g, ' ');
				var sTo = $(toBlock).text();
		    	// message separator here cannot be # like in scripts, changed to $..
		    	// also removed commas as we need to separate commandArray later.
	        	var setString = 'commandArray["SendEmail"]="'+sSubject+'$'+sBody+'$'+sTo+'"';
	        	setArray.push(setString);		      	
		    }
		    else if ($(this).attr('type') == 'send_sms') {
				var subjectBlock = $(this).children("field[name='TextSubject']")[0];
				var sSubject = $(subjectBlock).text().replace(/\,/g, ' ');
		    	// message separator here cannot be # like in scripts, changed to $..
		    	// also removed commas as we need to separate commandArray later.
	        	var setString = 'commandArray["SendSMS"]="'+sSubject+'"';
	        	setArray.push(setString);		      	
		    }
		    else if ($(this).attr('type') == 'start_script') {
				var pathBlock = $(this).children("field[name='TextPath']")[0];
				var sPath = $(pathBlock).text().replace(/\,/g, ' ');

				var paramBlock = $(this).children("field[name='TextParam']")[0];
				var sParam = $(paramBlock).text().replace(/\,/g, ' ');

				// message separator here cannot be # like in scripts, changed to $..
				// also removed commas as we need to separate commandArray later.
				var setString = 'commandArray["StartScript"]="'+sPath+'$'+sParam+'"';
				setArray.push(setString);		      	
		    }
		    else if ($(this).attr('type') == 'open_url') {
		    	var urlBlock = $(this).find("value[name='urlToOpen']")[0];
		    	var urlText = $(urlBlock).find("field[name='TEXT']")[0];
		    	var setString = 'commandArray["OpenURL"]="'+$(urlText).text()+'"';
	        	setArray.push(setString);		      	
		    }
			else if ($(this).attr('type') == 'writetolog') {
		    	var logBlock = $(this).find("value[name='writeToLog']")[0];
				var blockInfo = $(logBlock).children("block:first");
				var setString = "";
				if (blockInfo.attr("type")=="text") {
					var logText = $(blockInfo).find("field[name='TEXT']")[0];
					setString = 'commandArray["WriteToLogText"]="'+$(logText).text()+'"';
					setArray.push(setString);
				}
				else if (blockInfo.attr("type").indexOf("uservariables") >= 0) {
					var userVar = $(blockInfo).find("field[name='Variable']")[0];
					setString = 'commandArray["WriteToLogUserVariable"]="'+$(userVar).text()+'"';
					setArray.push(setString);
				}
				else if (blockInfo.attr("type").indexOf("switchvariables") >= 0) {
					var switchVar = $(blockInfo).find("field")[0];
					setString = 'commandArray["WriteToLogSwitch"]="'+$(switchVar).text()+'"';
					setArray.push(setString);
				}
				else if (blockInfo.attr("type").indexOf("variables") >= 0) {
					var deviceVar = $(blockInfo).find("field")[0];
					setString = 'commandArray["WriteToLogDeviceVariable"]="'+$(deviceVar).text()+'"';
					setArray.push(setString);
				}		
			}
		    else if ($(this).attr('type') == 'groupvariables') {
			   	var fieldA = $(this).find("field[name='Group']")[0];
			   	var fieldB = $(this).find("field[name='Status']")[0];
	        	var setString = "commandArray[Group:"+$(fieldA).text()+"]";
	        	setString += '="'+$(fieldB).text()+'"'; 
	        	setArray.push(setString);
		    }
		    else if ($(this).attr('type') == 'scenevariables') {
			   	var fieldA = $(this).find("field[name='Scene']")[0];
			   	var fieldB = $(this).find("field[name='Status']")[0];
	        	var setString = "commandArray[Scene:"+$(fieldA).text()+"]";
	        	setString += '="'+$(fieldB).text()+'"'; 
	        	setArray.push(setString);
		    }		    
		    else if ($(this).attr('type') == 'cameravariables') {
			   	var fieldA = $(this).find("field[name='Camera']")[0];
			   	var fieldB = $(this).find("field[name='Subject']")[0];
			   	var fieldC = $(this).find("field[name='NUM']")[0];
	        	var setString = "commandArray[SendCamera:"+$(fieldA).text()+"]";
	        	setString += '="'+ $(fieldB).text()+'" AFTER ' + $(fieldC).text().replace(/\,/g, ' '); 
	        	setArray.push(setString);
		    }		    
		    else if ($(this).attr('type') == 'setpointvariables') {
			   	var fieldA = $(this).find("field[name='SetPoint']")[0];
			   	var fieldB = $(this).find("field[name='NUM']")[0];
	        	var setString = "commandArray[SetSetpoint:"+$(fieldA).text()+"]";
	        	setString += '="'+$(fieldB).text()+'"'; 
	        	setArray.push(setString);
		    }		    
		  });
		  var conditionArray = [];
		  conditionArray.push(boolString);
	      return [conditionArray,setArray];     
      }
      
      function loadSelectedEvent(id) {
      		$.ajax({
			  	url: "json.htm?type=events&param=load&event="+id, 
			  	async: false, 
			  	dataType: 'json',
			  	success: function(data) {
				  	if (typeof data.result != 'undefined') {
						if (data.editortheme != 'undefined') {
							editor.setTheme(data.editortheme);
						}
				  		if (data.status=="OK") {
							$("#eventName").val(data.result[0].name);
							$("#interpreter").val(data.result[0].interpreter).prop('disabled', true);
							$("#eventType").val(data.result[0].type);
							if (data.result[0].eventstatus == '1') {
								$("#eventActive").prop('checked', true);
							}
							else {
								$("#eventActive").prop('checked',false);
							}
							if (data.result[0].interpreter == 'Blockly') {
								ResizeBlockyWindow();
								var xmltemp = data.result[0].xmlstatement;
								var xml = Blockly.Xml.textToDom(xmltemp);
								Blockly.mainWorkspace.clear();
								Blockly.Xml.domToWorkspace( Blockly.mainWorkspace, xml );
								$("#blockId").html(id);
							}
							else {
								if (data.result[0].interpreter == 'dzVents') {
									editor.getSession().setMode("ace/mode/lua");
									$("#eventType").val(data.result[0].type).prop('disabled', true);
								}
								else {
									editor.getSession().setMode("ace/mode/" + data.result[0].interpreter.toLowerCase());
									$("#eventType").val(data.result[0].type).prop('disabled', false);
								}
								editor.setValue("");
								editor.setValue(data.result[0].xmlstatement);
								editor.gotoLine(1);
								editor.scrollToLine(1, true, true, function () {});
								ResizeAceWindow();
							}
							$('#btnSave').attr("class", "btnstyle3");
							$('#btnDelete').attr("class", "btnstyle3");
						}
				  		else { bootbox.alert("Error loading event!");}
					}
				}
			});
	  }
	  
      function delete_block() {
        var id = document.getElementById("savedEvents").value;
        if ((id!=null)&&(id!="")) {
			bootbox.confirm($.t("Are you sure to delete this Event?\n\nThis action can not be undone..."), function(result) {
				if (result==true) {
					$.ajax({
						url: "json.htm?type=events&param=delete&event="+id, 
						async: false, 
						dataType: 'json',
						success: function(data) {
							if (typeof data != 'undefined') {
								if (data.status=="OK") {
									generate_noty('alert', '<b>Event Deleted<br>'+$("#eventName").val(), 2000);
									Blockly.mainWorkspace.clear();
									editor.setValue("");
									load_blocks();
									$("#eventName").val("");
									$("#interpreter").val("Blockly").prop('disabled', false);
									$("#eventType").val("All");
									ResizeBlockyWindow();
								}
							}
						}
					  });
					}
				});
		}
        else {
			bootbox.alert("Nothing selected!")
		}
	  }
	  
	  function load_blocks() {
		  var select = document.getElementById("savedEvents");
		  select.options.length = 0;
		  var interpreters = document.getElementById("interpreter");
		  interpreters.options.length = 0;
		  $.ajax({
		  	url: "json.htm?type=events&param=list", 
		  	async: false, 
		  	dataType: 'json',
		  	success: function(data) {
				var aInterpreters = data.interpreters.split(':');
				$.each(aInterpreters, function(i,item){
					var option = document.createElement("option");
					option.text = item;
					interpreters.appendChild(option); 
				});
			  	if (typeof data.result != 'undefined') {
				  	$.each(data.result, function(i,item){
						var option = document.createElement("option");
						option.text = item.name;
						option.value = item.id;
						option.style.color = 'red';
						if (item.eventstatus == '1') {
							option.style.color = 'black';
						}
						else if (item.eventstatus == '2') {
							option.style.color = 'purple';
						}						
						select.appendChild(option);
					});
				}
			}
		  });
	  }
	  
	function new_block() {
			var eventInterpreter = $("#interpreter").val().toLowerCase();
		$("#blockId").html("");
		Blockly.mainWorkspace.clear();
		editor.setValue("");
		$("#eventType").val("All");
		$("#eventType").prop('disabled', false);
		$("#eventName").val("");
		$("#savedEvents").val("");
		$("#interpreter").prop('disabled', false);
		$('#btnDelete').attr("class", "btnstyle3-dis");
		if ($("#interpreter").val() == "Blockly") {
			ResizeBlockyWindow();
		}
		else {
				if (eventInterpreter == "dzvents") {
					eventInterpreter = "lua";
					$("#eventType").prop('disabled', true);
				}
				editor.getSession().setMode("ace/mode/" + eventInterpreter);
			$.ajax({
				url: "json.htm?type=events&param=new&interpreter="+$("#interpreter").val()+"&eventtype="+$("#eventType").val(), 
				async: false, 
				dataType: 'json',
				success: function(data) {
					if (typeof data.template != 'undefined') {
						editor.getSession().setMode("ace/mode/" + eventInterpreter);
						editor.setValue(data.template);
						editor.gotoLine(1);
					}
					ResizeAceWindow();
				}
			});
		}
	}
      
      function save_block() {
      	var eventName = $("#eventName").val();
      	var eventInterpreter = $("#interpreter").val();
      	var id = "";
      	if (eventName) { 
      		var exists = false; 
      		var doSave = false;
      		$('#savedEvents option').each(function(){
	      		if (this.text == eventName) {
		      		exists = true;
					id=this.value;
		      	}
		     });
		     if (exists) {
			 	var answer = confirm("Overwrite "+eventName+"?")
			    if (answer){
					doSave = true;
				}
				else{
					doSave = false;
				}
			}
			else {doSave = true;}
      		if (doSave) {
				var logicArray;
				var editorTheme = "";
				if ($("#interpreter").val() == "Blockly") {
					var xml = Blockly.Xml.workspaceToDom( Blockly.mainWorkspace );
					var blockXml  = Blockly.Xml.domToText( xml );
					logicArray = parseXml(xml);
					if (typeof(logicArray)=='string') {
						var answerparts = logicArray.split(':');
						if (answerparts[0]=="err") {
							bootbox.alert(answerparts[1]);
							return;
						}
					}
					else if (typeof(logicArray)=='object') {
						logicArray = JSON.stringify(logicArray)
					}
				}
				else {
					logicArray = "";
					editorTheme = "&editortheme="+encodeURIComponent(editor.getTheme());
					blockXml = editor.getValue();
				}

				var isActive = 0;
				if ($('#eventActive').is(':checked')) {isActive = 1};
/*				
				$http({
					method: 'POST',
					url: 'event_create.webem',
					headers: {
						'Content-Type': 'multipart/form-data'
					},
					data: {
						name: encodeURIComponent(eventName),
						interpreter: encodeURIComponent($("#interpreter").val()),
						eventtype: encodeURIComponent($("#eventType").val()),
						xml: encodeURIComponent(blockXml),
						logicarray: encodeURIComponent(logicArray),
						eventid: id,
						eventstatus: isActive+editorTheme
					},
					transformRequest: function (data, headersGetter) {
						var formData = new FormData();
						angular.forEach(data, function (value, key) {
							formData.append(key, value);
						});
						var headers = headersGetter();
						delete headers['Content-Type'];
						return formData;
					}
				})
				.success(function (data) {
					alert(data);
					if (typeof data != 'undefined') {
						if (data.status=="OK") {
							generate_noty('information', '<b>Event saved:<br>'+eventName, 2000);
						}
						if (data.status=="ERR") {
							generate_noty('warning', '<b>Error while saving:<br>'+eventName, 2000);
						}
						load_blocks();
						var selIndex = 0;
						$('#savedEvents option').each(function(){
							if (this.text == eventName)
								$("#savedEvents").prop("selectedIndex",selIndex);
							selIndex++;
						});
						selIndex = 0;
						$('#interpreter option').each(function(){
							if (this.text == eventInterpreter)
								$("#interpreter").prop("selectedIndex",selIndex);
							selIndex++;
						});
					}
				})
				.error(function (data, status) {
					bootbox.alert("Save aborted!")
				});
*/
				var pdata="name="+encodeURIComponent(eventName)+"&interpreter="+encodeURIComponent($("#interpreter").val())+"&eventtype="+encodeURIComponent($("#eventType").val())+"&xml="+encodeURIComponent(blockXml)+"&logicarray="+encodeURIComponent(logicArray)+"&eventid="+id+"&eventstatus="+isActive+editorTheme;
				$.post("event_create.webem", pdata, function(data) {
					if (typeof data != 'undefined') {
						if (data.status=="OK") {
							generate_noty('information', '<b>Event saved:<br>'+eventName, 2000);
						}
						if (data.status=="ERR") {
							generate_noty('warning', '<b>Error while saving:<br>'+eventName, 2000);
						}
						load_blocks();
						var selIndex = 0;
						$('#savedEvents option').each(function(){
							if (this.text == eventName)
								$("#savedEvents").prop("selectedIndex",selIndex);
							selIndex++;
						});
						selIndex = 0;
						$('#interpreter option').each(function(){
							if (this.text == eventInterpreter)
								$("#interpreter").prop("selectedIndex",selIndex);
							selIndex++;
						});
					}
				})				
/*				
				$.ajax({
					url : "json.htm?type=events&param=create&name="+encodeURIComponent(eventName)+"&interpreter="+encodeURIComponent($("#interpreter").val())+"&eventtype="+encodeURIComponent($("#eventType").val())+"&xml="+encodeURIComponent(blockXml)+"&logicarray="+encodeURIComponent(logicArray)+"&eventid="+id+"&eventstatus="+isActive+editorTheme, 
					async: false, 
					dataType: 'json',
					success: function(data) {
						if (typeof data != 'undefined') {
							if (data.status=="OK") {
								generate_noty('information', '<b>Event saved:<br>'+eventName, 2000);
							}
							if (data.status=="ERR") {
								generate_noty('warning', '<b>Error while saving:<br>'+eventName, 2000);
							}
							load_blocks();
							var selIndex = 0;
							$('#savedEvents option').each(function(){
								if (this.text == eventName)
									$("#savedEvents").prop("selectedIndex",selIndex);
								selIndex++;
							});
							selIndex = 0;
							$('#interpreter option').each(function(){
								if (this.text == eventInterpreter)
									$("#interpreter").prop("selectedIndex",selIndex);
								selIndex++;
							});
						}
					}
				});
*/				
			}
			else {
				bootbox.alert("Save aborted!")
			}
		}
      	else {
			bootbox.alert('no event name entered!');
		}
      }

	  function show_states() {
	  	$.ajax({
	    	url : "json.htm?type=events&param=currentstates", 
	      	async: false, 
	      	dataType: 'json',
	      	success: function(data) {
		    	if (typeof data != 'undefined') {
					if (data.status=="OK") {
						var devicestates = "<div style='overflow:scroll; overflow-x: hidden; height: 400px;'><table><thead><tr><th align='left' style='padding-right: 80px;'>Idx</th><th align='left' style='padding-right: 80px;'>Name</th><th align='left' style='padding-right: 80px;'>Current state</th><th align='left' style='padding-right: 80px;'>Last updated</th><th align='left' style='padding-right: 10px;'>sValues</th></tr></thead><tbody>";
						if (typeof data.result != 'undefined') {
							
							$.each(data.result, function(i,item){
								if (item.name != "Unknown") {
									var oneitem = '<tr><td> '+item.id+' </td><td> '+item.name+' </td><td> '+item.value +' </td><td> '+item.lastupdate+' </td><td> '+item.svalues+'</td></tr>'; 
									devicestates += oneitem;
								}
							});
						}
						devicestates += "</tbody></table></div>";
						noty({
							text: devicestates,
							type: 'information',
							modal: true,
							buttons: [
							{addClass: 'btn btn-primary', text: 'Ok', onClick: function($noty) 
								{$noty.close();
									
								}
							}]
						});
				  	}
				  	else {
						bootbox.alert("Error getting current states, Is the Eventsystem Enabled?");
				  	}
				}
			}
		});
	  }
	  
	function block_export() {  
	
	}

	function block_import() {  
	
	}

	$(window).resize(function() {
		if ($("#blocklyDiv").css("display") != "none") ResizeBlockyWindow();
		if ($("#aceDiv").css("display") != "none") ResizeAceWindow();
	});

	function ResizeBlockyWindow()
	{
		if ($("#blocklyDiv").css("display") == "none") {
			$("#aceDiv").css("display","none");
			$("#blocklyDiv").css("display","");
			$(".blocklyToolboxDiv").css("display","");
		}
		$("#blocklyDiv").css("width", $(window).width()-250);
		$("#blocklyDiv").css("height", $(window).height()-20);
		$("#savedEvents").css("height", $(window).height()-343);
	}

	function ResizeAceWindow()
	{
		if ($("#aceDiv").css("display") == "none") {
			$("#blocklyDiv").css("display","none");
			$(".blocklyToolboxDiv").css("display","none");
			$("#aceDiv").css("display","");
		}
		$("#aceDiv").css("width", $(window).width()-250);
		$("#aceDiv").css("height", $(window).height()-20);
		$("#savedEvents").css("height", $(window).height()-343);
	}

	function SetSaveButton()
	{
		($("#eventName").val() == '') ? $('#btnSave').attr('class', 'btnstyle3-dis') : $('#btnSave').attr('class', 'btnstyle3');
	}
	
	$(document).ready(function() 
	{
		$.ajax({
			 url: "json.htm?type=command&param=getlanguage",
			 async: false, 
			 dataType: 'json',
			 success: function(data) {
				if (typeof data.language != 'undefined') {
					SetLanguage(data.language);
				}
				else {
					SetLanguage('en');
				}
			 },
			 error: function(){
			 }
		});
	
		ResizeBlockyWindow();
	});
      
    </script>

  </head>
  <body onload="init()">
    <xml id="toolbox" style="display: none">
   		
		<category name="Control">
	   		<block type="domoticzcontrols_if"></block>
	   		<block type="domoticzcontrols_ifelseif"></block>
   		</category>
   		<category name="Logic">
	   		<block type="logic_compare"></block>
	   		<block type="logic_operation"></block>
	   		<!--<block type="logic_boolean"></block>-->
	   		<block type="logic_states"></block>
	   		<block type="logic_set"></block>
	   		<block type="logic_setlevel"></block>
	   		<block type="logic_setafter"></block>
	   		<block type="logic_setdelayed"></block>
	   		<block type="logic_setrandom"></block>
	   		<block type="math_number"></block>
   		</category>
		<category name="Loop">
  <block type="controls_repeat_ext" id="PP1xWWodX6CKvEor(GH," x="88" y="38">
    <value name="TIMES">
      <shadow type="math_number" id="TYb81Ouygs*X/QdEF{3X">
        <field name="NUM">10</field>
      </shadow>
    </value>
  </block>
  <block type="controls_whileUntil" id="1L(2$G7AU(]_Wz{Zp{4k" x="87" y="162">
    <field name="MODE">WHILE</field>
  </block>
  <block type="controls_for" id="vN+!OA?Yeavhs`Md!}Lg" x="112" y="287">
    <field name="VAR" id="0y$Gy/vso8ilq[q#q8;2" variabletype="">i</field>
    <value name="FROM">
      <shadow type="math_number" id="e:rn3b{;Ywi!Sfs00g7-">
        <field name="NUM">1</field>
      </shadow>
    </value>
    <value name="TO">
      <shadow type="math_number" id="dDe#Gc3ZLs--t7pIJ/J7">
        <field name="NUM">10</field>
      </shadow>
    </value>
    <value name="BY">
      <shadow type="math_number" id="hu?8(8sHmHXo#_4VVcdP">
        <field name="NUM">1</field>
      </shadow>
    </value>
  </block>
  <block type="controls_forEach" id="+=m=;6*kSz+Yl3_}.%*3" x="137" y="412">
    <field name="VAR" id="([JrHA^8_^!l~E*IhORs" variabletype="">j</field>
  </block>
  <block type="controls_flow_statements" id="##^tSSR`%R|h^=HV=+iQ" disabled="true" x="162" y="562">
    <field name="FLOW">BREAK</field>
  </block>
   		</category>
		<category name="Math">
	   	  <block type="math_number">
    <field name="NUM">0</field>
  </block>
  <block type="math_arithmetic">
    <field name="OP">ADD</field>
    <value name="A">
      <shadow type="math_number">
        <field name="NUM">1</field>
      </shadow>
    </value>
    <value name="B">
      <shadow type="math_number">
        <field name="NUM">1</field>
      </shadow>
    </value>
  </block>
  <block type="math_single">
    <field name="OP">ROOT</field>
    <value name="NUM">
      <shadow type="math_number">
        <field name="NUM">9</field>
      </shadow>
    </value>
  </block>
  <block type="math_trig">
    <field name="OP">SIN</field>
    <value name="NUM">
      <shadow type="math_number">
        <field name="NUM">45</field>
      </shadow>
    </value>
  </block>
  <block type="math_constant">
    <field name="CONSTANT">PI</field>
  </block>
  <block type="math_number_property">
    <mutation divisor_input="false"></mutation>
    <field name="PROPERTY">EVEN</field>
    <value name="NUMBER_TO_CHECK">
      <shadow type="math_number">
        <field name="NUM">0</field>
      </shadow>
    </value>
  </block>
  <block type="math_round">
    <field name="OP">ROUND</field>
    <value name="NUM">
      <shadow type="math_number">
        <field name="NUM">3.1</field>
      </shadow>
    </value>
  </block>
  <block type="math_on_list">
    <mutation op="SUM"></mutation>
    <field name="OP">SUM</field>
  </block>
  <block type="math_modulo">
    <value name="DIVIDEND">
      <shadow type="math_number">
        <field name="NUM">64</field>
      </shadow>
    </value>
    <value name="DIVISOR">
      <shadow type="math_number">
        <field name="NUM">10</field>
      </shadow>
    </value>
  </block>
  <block type="math_constrain">
    <value name="VALUE">
      <shadow type="math_number">
        <field name="NUM">50</field>
      </shadow>
    </value>
    <value name="LOW">
      <shadow type="math_number">
        <field name="NUM">1</field>
      </shadow>
    </value>
    <value name="HIGH">
      <shadow type="math_number">
        <field name="NUM">100</field>
      </shadow>
    </value>
  </block>
  <block type="math_random_int">
    <value name="FROM">
      <shadow type="math_number">
        <field name="NUM">1</field>
      </shadow>
    </value>
    <value name="TO">
      <shadow type="math_number">
        <field name="NUM">100</field>
      </shadow>
    </value>
  </block>
  <block type="math_random_float"></block>
   		</category>
   		<category name="Time">
	   		<block type="logic_timeofday"></block>
	   		<block type="logic_weekday"></block>
	   		<block type="logic_timevalue"></block>
	   		<block type="logic_sunrisesunset"></block>
   		</category>
   		<category name="Messages">
   			<block type="send_notification"></block>
   			<block type="send_email"></block>
   			<block type="send_sms"></block>
   			<block type="text"></block>
   			<block type="open_url"></block>
   			<block type="url_text"></block>
   			<block type="start_script"></block>
   		</category>
   		<category name="Security">
   			<block type="security_status"></block>
   		</category>
		<category name="User variables">
			<block type="uservariablesAF"></block>
			<block type="uservariablesGL"></block>
			<block type="uservariablesMR"></block>
			<block type="uservariablesSZ"></block>
			<block type="math_number"></block>
			<block type="text"></block>
		</category>
		<category name="Debug/log">
		   	<block type="writetolog"></block>
			<block type="text"></block>
	   	</category>
   		<category name="Devices">   		
		   	<category name="Switches">
			   	<block type="switchvariablesAF"></block>
			   	<block type="switchvariablesGL"></block>
			   	<block type="switchvariablesMR"></block>
			   	<block type="switchvariablesSZ"></block>
			</category>   		
		   	<category name="Temperature">
			   	<block type="temperaturevariables"></block>
		   	</category>	   		   		
		   	<category name="Humidity">
			   	<block type="humidityvariables"></block>
		   	</category>	
		   	<category name="Dewpoint">
			   	<block type="dewpointvariables"></block>
		   	</category>	   		   		
		   	<category name="Barometer">
			   	<block type="barometervariables"></block>
		   	</category>	
		   	<category name="Weather">
			   	<block type="weathervariables"></block>
		   	</category>
		   	<category name="Utility">
			   	<block type="utilityvariables"></block>
			   	<block type="utilityvariablesAF"></block>
			   	<block type="utilityvariablesGL"></block>
			   	<block type="utilityvariablesMR"></block>
			   	<block type="utilityvariablesSZ"></block>
		   	</category>
		   	<category name="Scenes/groups">
			   	<block type="scenevariables"></block>
			   	<block type="groupvariables"></block>
		   	</category>
		   	<category name="Cameras">
			   	<block type="cameravariables"></block>
		   	</category>
		   	<category name="SetPoints">
			   	<block type="setpointvariables"></block>
		   	</category>
		   	<category name="ZWave Alarms">
			   	<block type="zwavealarms"></block>
		   	</category>
		</category>
    </xml>
    <div id="maindiv" class="container-fluid">
		<div class="row-fluid">
			<table id="saveTable" border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td class=container" valign="top">
					<menu type="context" id="acemenu">
						<menu label="Editor Theme">
							<menuitem label="Ambiance" type="radio" onclick="editor.setTheme('ace/theme/ambiance');"></menuitem>
							<menuitem label="Chaos" type="radio" onclick="editor.setTheme('ace/theme/chaos');"></menuitem>
							<menuitem label="Chrome" type="radio" onclick="editor.setTheme('ace/theme/chrome');"></menuitem>
							<menuitem label="Cobalt" type="radio" onclick="editor.setTheme('ace/theme/cobalt');"></menuitem>
							<menuitem label="Eclipse" type="radio" onclick="editor.setTheme('ace/theme/eclipse');"></menuitem>
							<menuitem label="Merbivore" type="radio" onclick="editor.setTheme('ace/theme/merbivore');"></menuitem>
							<menuitem label="Mono Industrial" type="radio" onclick="editor.setTheme('ace/theme/mono_industrial');"></menuitem>
							<menuitem label="Monokai" type="radio" onclick="editor.setTheme('ace/theme/monokai');"></menuitem>
							<menuitem label="Pastel on dark" type="radio" onclick="editor.setTheme('ace/theme/pastel_on_dark');"></menuitem>
							<menuitem label="Terminal" type="radio" onclick="editor.setTheme('ace/theme/terminal');"></menuitem>
							<menuitem label="Tomorrow" type="radio" onclick="editor.setTheme('ace/theme/tomorrow');"></menuitem>
							<menuitem label="Vibrant_ink" type="radio" onclick="editor.setTheme('ace/theme/vibrant_ink');"></menuitem>
							<menuitem label="XCode" type="radio" checked="checked" onclick="editor.setTheme('ace/theme/xcode');"></menuitem>
						</menu>
						<menuitem label="Auto Complete" type="checkbox" checked="true" onclick="editor.setOptions({enableLiveAutocompletion: this.getAttribute('checked')=='false'}); this.setAttribute('checked',this.getAttribute('checked')=='false');"></menuitem>
					</menu>
					<div id="aceDiv" class="ui-corner-all" style="display:none;" contextmenu="acemenu"></div>
					<div id="blocklyDiv"></div>
				</td>
				<td style="width:250px" valign="top">
					<label for="eventName">Event name:</label><br>
					<input type="input" id="eventName" name="eventName" oninput="SetSaveButton();" onchange="SetSaveButton();" style="width: 12em; padding: .2em;" class="text ui-widget-content ui-corner-all" /><br>
					<p>
					<select name="interpreter" id="interpreter" class="ui-widget-content ui-corner-all" onchange="new_block();" style="width: 12em; padding: .2em; margin-top: 0.4em;">	
						<option selected="selected">Blockly</option>
						<option>Lua</option>
						<option>dzVents</option>
						<option>Python</option>
					</select>
					<p>
					<select name="eventType" id="eventType" class="ui-widget-content ui-corner-all" style="width: 12em; padding: .2em;">
					  <option selected="selected">All</option>
					  <option>Device</option>
					  <option>Security</option>
					  <option>Time</option>
					  <option>UserVariable</option>
					</select>
					<p>
					<label for="eventActive">Event active:</label>
					<input type="checkbox" id="eventActive" name="eventActive"/>
					</p>
					<p>
					<a class="btnstyle3-dis" id="btnSave" href="javascript:save_block()">Save</a>
					<a class="btnstyle3" href="javascript:new_block()">New</a>
					</p>
					<p>
					<label for="savedEvents">Saved events:</label><br>
					<select size="20" width="100%" style="width: 100%" id="savedEvents" name="savedEvents" onchange="loadSelectedEvent(this.value);"></select>
					</p>
					<p>
					<a class="btnstyle3-dis" id="btnDelete" style="width: 80%" href="javascript:delete_block()">Delete selected</a></br>
					<a class="btnstyle3" style="width: 80%; margin-top: 0.4em;" href="javascript:show_states()">Show current states</a>
					</p>
					<div id="blockId" style="display:none;"/>
				</td>
			</tr>
			</table>
		</div>
	</div>
  </body>
</html>
Image

Image

eventsframe.html

pvm
Posts: 949
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Re: Math operators and Blocking

Post by pvm » Wednesday 06 December 2017 21:38

Are these fuctional?
Can upgrading the complete blockly code also fix the 'else' issue (not really functioning as and else statement)
Synology NAS, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

Mesomorf
Posts: 4
Joined: Saturday 02 April 2016 9:59
Target OS: Windows
Domoticz version:
Contact:

Re: Math operators and Blocking

Post by Mesomorf » Sunday 17 December 2017 15:55

pvm wrote:
Wednesday 06 December 2017 21:38
Are these fuctional?
Tried the Math function. Made simple test to add a "1 + 1" value to variable, but it is not updating the variable. So no, it is not functional.

wuschels
Posts: 3
Joined: Saturday 30 December 2017 21:20
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Math operators and Blocking

Post by wuschels » Saturday 30 December 2017 23:47

ebretteville you are my sunshine !
That is exactly what i am looking for a long time.
i've tried to implement the original google code, but i was not succesful.
in January i will try it with your file.
is there somthing else to do....?
1x Pi1 (cgminer)
1X Pi2 (Pi-Hole)
3x Pi3 ( Nextcloud, Domoticz, Kodi)
1x AMD Quad-core, 20Gbyte RAM (SuSE-Linux, Vmware....)

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Thursday 11 January 2018 15:21

Don't know, blockly is from my point of view no really well documented. I can't find a complete list of available blocks. Also tried to do an avarage with some sensors values but it says average of list so it's ok for what i want to do but I can't find the list block. Also for @Mesomorf maybe you have to use the write to log block and write to the idx the result of the operation.

wuschels
Posts: 3
Joined: Saturday 30 December 2017 21:20
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Math operators and Blocking

Post by wuschels » Thursday 18 January 2018 12:54

Blockly ist documented at: https://developers.google.com/blockly/
There is a Online-Guide where you can test your blockly-scripts.
It is also possible to make your own blocks, but it is not so easy....
I managed to implement "Loops", "Math" and "Variables" into domoticz.
It seems to work, but i do have problems with "variables". It seem that blockly-variables are not compatible with domitcz-user-variables..
1x Pi1 (cgminer)
1X Pi2 (Pi-Hole)
3x Pi3 ( Nextcloud, Domoticz, Kodi)
1x AMD Quad-core, 20Gbyte RAM (SuSE-Linux, Vmware....)

Xztraz
Posts: 129
Joined: Tuesday 31 January 2017 22:54
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Math operators and Blocking

Post by Xztraz » Thursday 22 February 2018 22:52

In the long run a full blockly->lua editor would be awesome. Start with blockly and if more advanced stuff is needed. Just switch the code to lua and continue there. Great way to learn coding.

JoergZ
Posts: 6
Joined: Thursday 14 September 2017 8:42
Target OS: Raspberry Pi
Domoticz version: V3.8153
Contact:

Re: Math operators and Blocking

Post by JoergZ » Monday 19 March 2018 16:58

I downloaded toolbox.xml and eventsframe.html to /home/pi/domoticz/www/ and restartet domoticz. But nothing changed. There is no Math library or something else new block at the blockly editor. What have I to do, to use math?

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Monday 19 March 2018 18:51

viewtopic.php?p=175156&sid=826759ff4357 ... 8a#p160576
With loops, to be placed at /home/pi/domoticz/www/ in a file named eventsframe.html
Attached file has been updated

JoergZ
Posts: 6
Joined: Thursday 14 September 2017 8:42
Target OS: Raspberry Pi
Domoticz version: V3.8153
Contact:

Re: Math operators and Blocking

Post by JoergZ » Monday 19 March 2018 20:18

Please, no repetitions, use some other descriptive words. I don't understand. A loop is a programming element. But what is the context to the path of the files toolbox.xml and eventsframe.html.

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Monday 19 March 2018 20:46

Forget toolbox.xml and place eventsframe in the location described in my last message. That will do the trick

Sent from my MI MAX using Tapatalk


salopette
Posts: 35
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: Math operators and Blocking

Post by salopette » Saturday 07 April 2018 7:56

Hello, where does the file have to be changed that I get the math?
The file is also no longer found?
Thank you

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Saturday 07 April 2018 9:12

Read my previous message and get the file in my first post that I updated

Sent from my MI MAX using Tapatalk


Captayne
Posts: 2
Joined: Sunday 08 July 2018 9:56
Target OS: Windows
Domoticz version:
Contact:

Re: Math operators and Blocking

Post by Captayne » Sunday 08 July 2018 10:04

Does ebrettvilles toolbox.eml and eventsframe.htm. work for everybody?
I have tried it but with no effect. The linked html file has gone from the location. Please update it.

Is there another location for math in blockly for domoticz?
Possibly one with better documentation about installation and usage?
Thank you all.

Captayne
Posts: 2
Joined: Sunday 08 July 2018 9:56
Target OS: Windows
Domoticz version:
Contact:

Re: Math operators and Blocking

Post by Captayne » Sunday 08 July 2018 15:01

Can someone post the lastest eventsframe.html?
Thank you soo much!
Andy

ebretteville
Posts: 29
Joined: Sunday 10 January 2016 15:41
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Cherbourg - Caen | France
Contact:

Re: Math operators and Blocking

Post by ebretteville » Sunday 08 July 2018 16:28

Will do it later, I'm in the train

Sent from my MI MAX using Tapatalk


salopette
Posts: 35
Joined: Tuesday 07 March 2017 22:03
Target OS: Raspberry Pi
Domoticz version: V3.6882
Location: Germany
Contact:

Re: Math operators and Blocking

Post by salopette » Sunday 12 August 2018 21:00

Hello ebretteville, is there an update ???

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests