Timeline picker to setup heating, light and so on

Hi Oliver,
can you insert the following logInfo… in the rule file at this postion and post the log?

            while ((countScale < 9) && (!stopLoop)) {
                logInfo('check',String::format("%s | %s",currKey,switchPlan))   // insert this line
                if (switchPlan.contains(countScale.toString + '":')) {

You wrote:

The logs give
Item ‘TransferItem’ received command {“1”:{“key”:“17”,“value”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0]},“99”:“OFF,ON”}

Have you added an additional log command or does this entry appear in the log file by itself?

Mine was doing the same thing with this error. I found that i was trying to access my timepicker HTML from an external network and it was not saving the times or updating the timepicker. Once i accessed from my local network it fixed it.

You want the timepicker to update something like this

2018-11-22 12:00:30.021 [vent.ItemStateChangedEvent] - TransferItem changed from {"1":{"key":"1","value":"OFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"},"2":{"key":"2","value":",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,3,3,3,3,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"},"3":{"key":"3","value":"OFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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0,0"},"6":{"key":"6","value":"OFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"},"7":{"key":"7","value":"OFF,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"},"99":"OFF,Zone1,Zone2,Zone3,Zone4"}

This is how mine updates. But i have mine set for every day is seperate. Not grouping them.

Hi Torsten,
The entry I was refering to was the entry found in the events.log when I save the schedule from the time-line-picker page.

I have now added the logInfo which shows the following in the openhab.log:
2018-11-23 18:30:30.032 [INFO ] [eclipse.smarthome.model.script.check] - 17 | {“1”:{“key”:“17”,“value”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0]},“99”:“OFF,ON”}

2018-11-23 18:30:30.048 [INFO ] [eclipse.smarthome.model.script.check] - 17 | {“1”:{“key”:“17”,“value”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0]},“99”:“OFF,ON”}

2018-11-23 18:30:30.053 [ERROR] [se.smarthome.model.script.timepicker] - error in transfer string
I think the problem is coming from the [ and ] as delimiter of the “value” instead of ".
I will look why I get these delimiters.

Hi Oliver,
it’s realy strange. Your log looks good.
Please post your complete rule file and i will view this.

In the first you can replace currKey in the additional log line through countScale and also post the result.

logInfo('check',String::format("%s | %s",countScale,switchPlan))   // insert this line

Amazing how you are responsive Torsten :slight_smile:

Here is the result with countScale
2018-11-23 19:16:00.042 [INFO ] [eclipse.smarthome.model.script.check] - 1 | {“1”:{“key”:“17”,“value”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0]},“99”:“OFF,ON”}

2018-11-23 19:16:00.069 [INFO ] [eclipse.smarthome.model.script.check] - 2 | {“1”:{“key”:“17”,“value”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0]},“99”:“OFF,ON”}

2018-11-23 19:16:00.081 [ERROR] [se.smarthome.model.script.timepicker] - error in transfer string

and my rules is pretty much coming from github version 0.5 and that is:
import org.eclipse.smarthome.model.script.ScriptServiceUtil
import java.util.HashMap
import java.util.ArrayList

val HashMap<String,ArrayList> timePicker = newHashMap(
“TransferItem” -> newArrayList(‘Terrarium1’,‘Terrarium2’)
)

rule “check switchpoints 1”
when
// Time cron “0 0/15 * 1/1 * ? *”
Time cron “0/15 * * ? * * *” // for debug, trigger eatch 15 seconds
then
var Number currTimeInterval = (now.getMinuteOfDay() / 15).intValue
var Number currDay = now.getDayOfWeek()

gTimepicker.members.forEach[ currSwitchPlan |
    if ((currSwitchPlan.state !== NULL) && (timePicker.keySet().contains(currSwitchPlan.name))) {
        var String switchPlan = (currSwitchPlan.state as StringType).toString
        var String currKey = currDay.toString

        // check the different week plans 15,17,67; e.g mo-fr, ...
        if (switchPlan.contains('"key":"17"')) currKey = "17"
        if (switchPlan.contains('"key":"15"') && (currDay > 0 && currDay < 6)) currKey = "15"
        if (switchPlan.contains('"key":"67"') && (currDay > 5 )) currKey = "67"

        // determine the scale number in transfer string
        var Number countScale = 1
        var Boolean stopLoop = false
        while ((countScale < 9) && (!stopLoop)) {
                            logInfo('check',String::format("%s | %s",countScale,switchPlan))   // for debugging
            if (switchPlan.contains(countScale.toString + '":')) {
                if (transform("JSONPATH", "$." + countScale.toString + ".key", switchPlan) == currKey) {
                    countScale = countScale -1
                    stopLoop = true
                }
                countScale = countScale + 1
            } else {
                // error in transfer string
                logError("timepicker","error in transfer string")
                countScale = (-1)
                stopLoop = true
            }
        }
        if (countScale != (-1)) {
            var String[] switchStates = (transform("JSONPATH", "$." + "99", switchPlan.toString)).split(',')
            var ArrayList<String> itemToSwitch = new ArrayList(timePicker.get(currSwitchPlan.name))

            // extract switch states of dataset; jsonpath is realy unflexible so string operation are used
            var String dataSetOfDay = (transform("JSONPATH", "$." + countScale.toString, switchPlan))
            var Number[] switchPlanOfDay = (dataSetOfDay.substring(dataSetOfDay.indexOf('value')+7,dataSetOfDay.length-2)).split(',')

            if (!(itemToSwitch.size() == 1 && "".equals(itemToSwitch.get(0)))) {
                itemToSwitch.forEach [ iTS |
                    var currItem = ScriptServiceUtil.getItemRegistry.getItem(iTS) as GenericItem
                    var newState = switchStates.get(Integer::parseInt(switchPlanOfDay.get(currTimeInterval)))
                    // send only commands when current state differenced from new state
                    if (currItem.state.toString != newState) currItem.sendCommand(newState.toString)
                ]
            }
        }
    }
]

end

I think, i have found the problem. :scream:

You see the double quotes? They are different.
I mean this is the problem.

The transfer string is transmited with your double quotes and in the rule file is my version of double quotes.
Please try ro replace the double quotes in this line of rule file with your keyboard:

if (switchPlan.contains(countScale.toString + ‘":’)) {

Then check what happens.

I have overtyped the " from the keyboard but same thing !?!?!

In the log should I get {“1”:{“key”:“17”,“value”:[0,0,… or {“1”:{“key”:“17”,“value”:"0,0,…?
because on the above examples the [ is replaced by a "

I even tried
if (switchPlan.contains(countScale.toString + ‘]:’)) {

but I get at that time only the first key.

This is right:

{“1”:{“key”:“17”,“value”:[0,0,…

I remember that I once had a similar problem when writing on a linux machine when copy and past.
I had to replace the double quotes manuell.

Perhaps you can replace the part auf rules file with this and post the log. It’s a little bit try and error. But i have no other idea.

        while ((countScale < 9) && (!stopLoop)) {
            logInfo('check',String::format("%s | %s",countScale,switchPlan))   // for debugging
            if (switchPlan.contains(countScale.toString + '":')) {
                logInfo('a1','111')
                var String x1 = transform("JSONPATH", "$." + countScale.toString + ".key", switchPlan)
                logInfo('a2',x1)
                if (x1 == currKey) {
                    logInfo('a3','222')
                    countScale = countScale -1
                    stopLoop = true
                }
                countScale = countScale + 1
            } else {

Got some Problem .

Rule Version 0.5

2018-11-25 15:01:15.008 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'check switchpoints 1': 60

Items are:

Group gTimepicker   (All)
String TransferItem "[%s]"      (gTimepicker)
Switch Thermostat1 "Timeline Thermostat 1" (gTimepicker)
Switch Thermostat2 "Timeline Thermostat 2" (gTimepicker)
Switch LightSwitch45 "Timeline Lichtschalter" (gTimepicker)

TranserItem shows

	"{\"1\":{\"key\":\"1\",\"value\":\",,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1\"},\"2\":{\"key\":\"2\",\"value\":\",,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1\"},\"3\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F,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF,OFF\"},\"7\":{\"key\":\"7\",\"value\":\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1\"},\"99\":\"OFF,ON\"}"


Thanks for Help

Hi Martin,

delete the group gTimepicker as follow:

Group gTimepicker (All)
String TransferItem “[%s]” (gTimepicker)
Switch Thermostat1 “Timeline Thermostat 1”
Switch Thermostat2 “Timeline Thermostat 2”
Switch LightSwitch45 “Timeline Lichtschalter”

Hello Torsten.

after deleting the Group association, if got another Problem.

2018-11-26 08:27:30.007 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'check switchpoints 1': For input string: ""

the TransferItem has the State

{"1":{"key":"1","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,0"},"2":{"key":"2","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1,1,1"},"3":{"key":"3","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1,1,1"},"4":{"key":"4","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1,1,1"},"5":{"key":"5","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1,1,1"},"6":{"key":"6","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1,1,1"},"7":{"key":"7","value":",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"},"99":"OFF,ON"}

its not OK in my opinion.

What can i do???

Danke

Hi Martin,

you are right. The state of the string is wrong.

The correct format is - in this example for monday to sunday; key = 17:

{“1”:{“key”:“17”,“value”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,0]},“99”:“OFF,ON”}

It’s a complete other structur. Did you really download the switchPointSet.js from development brunch on gitlab? Have you experimented with different versions? In this case you should change temporarly the timeline and save this new value.
Please change temporarly the url parameter for y axis to 17. At the next call of widget you will answer the sequrity question. Please answer yes and now save the timeline with one or two set points!
Now you can your call the widget thi your previous url parameter for y axis (1,2,3,4,5,6,7) and answer the security question again with yes. One or two set points, save …

Then look the TransferItem state.

Now if got some time for TESTS.

Her the Results.

I downloaded the Files again from the Development Branch --> no change.

Then i read the hole Tread again.

If i put the Webview item with both Times the IP Address in the Sitemap --> the TransferItem is malformed
If i put the Webview item with the Networkname in front and then the IP Address in --> the Transferitem works.

BUT:
in both Times when i refresh the Browser. The bar in the Website were gone.

My Testsystem is OPENHABIAN, but that could not make a different.

And Switchpoints i could not see make no sense.

MAPDB is installed.

Any Idea.

Thanks for the good Help!!!

you have to have the html files in your /conf/html folder

This is my sitemap

Webview url="/static/time-line-picker/index.html?ip=192.168.0.143:8080&transferItem=TransferItem&states=OFF,Zone1,Zone2,Zone3,Zone4&yAxisLabel=1,2,3,4,5,6,7" icon="calendar" height=13
							
								}

this is my rules

import org.eclipse.smarthome.model.script.ScriptServiceUtil
import java.util.HashMap
import java.util.ArrayList

// timeline/ timepicker control
// version 0.4
// ToSe 
//
// init values & customize for you own enviroment
// -----------------------------------------------------------------------------------------------------------
//
//
// requirements: MapDB
// -----------------------------------------------------------------------------------------------------------
//  String xxxSwitchPoints                   "xxxxxx [%s]"                                               (gTimepicker)
//  
//  Group  gTimepicker                                                                                   (All)
//
//
//
// data structure
// -----------------------------------------------------------------------------------------------------------
// val HashMap<String,  ArrayList<String>> timePicker = newHashMap(
//     "TransferItem1" -> newArrayList('item1','item2',...)                 // enum all to control
//     "TransferItem2" -> newArrayList('item3')
//     ...                                                                  // enum all TransferItems and his 
// )
//
//


val HashMap<String,ArrayList<String>> timePicker = newHashMap(
    "TransferItem"   -> newArrayList('SprinklerZone'))

rule "check switchpoints 1"
when
		Time cron "0 0/15 * 1/1 * ? *"
//	  	Time cron "0/10 * * ? * * *"        // for debug, trigger each 10 seconds
then

 if(SprinklerSystemSchedule.state == ON)
 {
				


    var Number currTimeInterval = ((now.getMinuteOfDay() / 15) + 1).intValue
    var Number currDay = now.getDayOfWeek()
	logInfo("timepicker","Running Rule")

	
    gTimepicker.members.forEach[ currSwitchPlan |
		
        if (currSwitchPlan.state !== NULL) {
            var String switchPlan = (currSwitchPlan.state as StringType).toString
            var String currKey = currDay.toString


            // check the differnt week plans 15,17,67; e.g mo-fr, ...
            if (switchPlan.contains('"key":"17"')) currKey = "17"
            if (switchPlan.contains('"key":"15"') && (currDay > 0 && currDay < 6)) currKey = "15"
            if (switchPlan.contains('"key":"67"') && (currDay > 5 )) currKey = "67"

            // determine the scale number in transfer string
            var Number countScale = 1
            var Boolean stopLoop = false
            while ((countScale < 9) && (!stopLoop)) {
				
                if (switchPlan.contains(countScale.toString + '":')) {
					
                    if (transform("JSONPATH", "$." + countScale.toString + ".key", switchPlan) == currKey) {
						
                        countScale = countScale -1
                        stopLoop = true
						
                    }
                    
					
                } else {
                    // error in transfer string
                    logError("timepicker","error in transfer string")
                    countScale = (-1)
                    stopLoop = true
                }
			countScale = countScale + 1
            }

            if (countScale != (-1)) {
                var String[] switchPoints = (transform("JSONPATH", "$." + currKey + ".value", switchPlan)).split(',')
				
                var String[] switchStates = (transform("JSONPATH", "$." + "99", switchPlan)).split(',')
				
                var ArrayList<String> itemToSwitch = new ArrayList(timePicker.get(currSwitchPlan.name))
				

                if (!(itemToSwitch.size() == 1 && "".equals(itemToSwitch.get(0)))) {
				
                    itemToSwitch.forEach [ iTS |
                        var currItem = ScriptServiceUtil.getItemRegistry.getItem(iTS) as GenericItem
						
                        var newState = switchStates.get(Integer::parseInt(switchPoints.get(currTimeInterval)))
						
						
						logInfo("Send", currItem.state.toString)
						logInfo("Send", newState.toString)
						
						
						
                        // send only commands when current state differenced from new state
                        if (currItem.state.toString != newState) {
						currItem.sendCommand(newState.toString)
						logInfo("Send", "Sending information")
						
						}
						
                    ]
                }
            }
        }
    ]
	
}
	
end

//*************************************************************************
rule "Sprinkler Time Picker"
when
  Item SprinklerZone received command
then
  
  switch SprinklerZone {
    

	
    case SprinklerZone.state == "Zone1" : {
      // activate zone 1
	  logInfo("Zone1","Turning on Zone 1")
	  onHours1.sendCommand(0)
	  SprinklerSystemZone1.sendCommand(ON)
    }
    case SprinklerZone.state == "Zone2" : {
      // activate zone 2
	  logInfo("Zone2","Turning on Zone 2")
	  onHours2.sendCommand(0)
	  SprinklerSystemZone2.sendCommand(ON)
    }
    case SprinklerZone.state == "Zone3" : {
      // activate zone 3
	  logInfo("Zone3","Turning on Zone 3")
	  onHours3.sendCommand(0)
	  SprinklerSystemZone3.sendCommand(ON)
    }
    case SprinklerZone.state == "Zone4" : {
      // activate zone 4
	  logInfo("Zone4","Turning on Zone 4")
	  onHours4.sendCommand(0)
	  SprinklerSystemZone4.sendCommand(ON)
    }
	case SprinklerZone.state == "OFF" : {
	  // turn off zones
	  logInfo("Zone","Turning off Zones")
	  gIrrigation.members.forEach[
	  sendCommand(OFF)
	  ]
	 }
  }
  
  
end

This is my items

Group gTimepicker (mapDB)


//*********************************
//Time PIcker
//***********


String TransferItem "[%s]"      (gTimepicker)
String SprinklerZone "[%s]"		

With this setup it works ONLY if i access the timepicker on my local network.

If i access it externally using my public IP or a domain, it will not save the timepicker settings. When i refresh, the selections are gone and i get errors.

You MUST access using a local address.

Thanks Christopher for the Information, but i access the Webpage that i postet from the intern Network.

And the Times that i selectet worked now, but i dont see them thats the only Problem thats left.

Update: I build a Sitemap with both URL. And when i pick the one with the Networkname to select the Time, after the Refresh i see it in the other URL with the IP Address.

No Idea whats going on.

Cu Martin

Martin, to check can you clear the browser cash and then refresh the site?

The times you are selected working well. But in the widget is nothing to see?
When you select ON its also in the current state blue and now you click the timeline and nothing happens?
Please clear the cash and try again.

Hy Torsten.

Here a Screenshot.

The First Window is the URL with both IP (as described) --> here are the Bars shown, but the saved TranferItem is corrupt.

The Second Window is the URL with the Networkname in Front. --> here i can choose the Time and the work well, but after the Refresh the Bars are gone.

I cleared the Cache, and test it an 2 OS with 2 different Browser on each System. (4 Browser) no Bars on the Second Window.

Im complete.

No Ideas left. :exploding_head:

Can you post the both webview urls?

Hello Torsten.

here is the hole Sitemap.

sitemap timeline label="Timeline TEST" 
{Frame label="Datum" {
		Text item=Date {
		Group item=gAstro
		Group item=gMond}
}//Ende Date
Frame label="URL with IP Adress"{Webview url="http://192.168.0.75:8080/static/time-line-picker/index.html?ip=192.168.0.75:8080&transferItem=TransferItem&states=OFF,ON&yAxisLabel=1,2,3,4,5,6,7" height=13}
 
Frame label="URL with Network Name"{Webview url="http://openhabian:8080/static/time-line-picker/index.html?ip=192.168.0.75:8080&transferItem=TransferItem&states=OFF,ON&yAxisLabel=1,2,3,4,5,6,7" height=13}
			    				
}//Ende Sitemap

bye