{"size": 1314, "ext": "js", "max_stars_repo_path": "UI/scripts/.archive/smarthome-log/log-shading.js", "max_stars_repo_name": "florian-h05/openhab-conf", "max_stars_repo_stars_event_min_datetime": "2021-06-12T16:51:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-27T18:47:34.000Z", "max_issues_repo_path": "UI/scripts/.archive/smarthome-log/log-shading.js", "max_issues_repo_name": "florian-h05/openhab-conf", "max_issues_repo_issues_event_min_datetime": "2021-07-10T10:41:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-06T16:11:18.000Z", "max_forks_repo_path": "UI/scripts/.archive/smarthome-log/log-shading.js", "max_forks_repo_name": "florian-h05/openhab-conf", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 46.9285714286, "max_line_length": 186, "alphanum_fraction": 0.7153729072}
/*
This script logs knx shading to the InfluxDB smarthome log.
Configure the suffix of the shading state item in line 15. 
This script gets the rule triggering item.
This script is used directly in the rule.
Copyright (c) 2021 Florian Hotze under MIT License
*/

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID)
var Exec = Java.type('org.openhab.core.model.script.actions.Exec')
var Duration = Java.type('java.time.Duration')

function logShading (itemName) {
  var actualState = itemRegistry.getItem(itemName).getState()
  // logger.info(itemName + ' actual state is: ' + actualState)
  var deviceName = itemName.replace('_BeschStat', '')
  if (actualState === ON) {
    Exec.executeCommandLine(Duration.ofSeconds(30), '/usr/bin/python3', '/etc/openhab/scripts/openhab-log-influxdb.py', '-t knx', '-d ' + deviceName, '-l Aut. Verschattung aktiviert.')
    // logger.info('logged ' + deviceName + ' shading on to the smarthome-log')
  }
  if (actualState === OFF) {
    Exec.executeCommandLine(Duration.ofSeconds(30), '/usr/bin/python3', '/etc/openhab/scripts/openhab-log-influxdb.py', '-t knx', '-d ' + deviceName, '-l Aut. Verschattung deaktiviert.')
    // logger.info('logged ' + deviceName + ' shading off to the smarthome-log')
  }
}

logShading(event.itemName)
