No instant converter found for type: org.python.core.PyFunction

I’m at the very beginning to learn the new automation engine starting with the conversion from some basic routines.

With the following code I try to convert some lambdas I had in Rules DSL. Unfortunately I’m not coming to test the code itself as I’m already struggling in the call of the function:

30-Aug-2020 11:52:09.981 [INFO ] [jsr223.jython.Test: Generisch       ] - Test Rule getriggert
30-Aug-2020 11:52:11.566 [ERROR] [jsr223.jython.Test: Generisch       ] - Traceback (most recent call last):
  File "/etc/openhab2/automation/lib/python/core/", line 51, in wrapper
    return fn(*args, **kwargs)
  File "<script>", line 61, in TestRule
IllegalArgumentException: java.lang.IllegalArgumentException: No instant converter found for type: org.python.core.PyFunction

The problem is the line:

  NachtBeginn = DateTime(fnNachtBeginn)

but this one also doesn’t work

  NachtEnde = fnNachtEnde

I don’t know how to solve that.

import time

from core.rules import rule
from core.triggers import when
from import to_joda_datetime

from org.joda.time import DateTime

# prüfen, ob es Tag oder Nacht ist
def fnNachtBeginn():
		now =

		Zeit2200Uhr = now.withTimeAtStartOfDay.plusHours(22)	# 22 Uhr abends

		#Sonnenuntergang = DateTime(ir.getItem("dtm_Astro_Sonnenuntergang").state).zonedDateTime.toInstant.toEpochMilli
		Sonnenuntergang = to_joda_datetime(ir.getItem("dtm_Astro_Sonnenuntergang")).millis

		Differenz = Sonnenuntergang - now.millis

		NachtBeginn = now.plusMillis(Differenz.intValue / 2)	# Mitte von civilDusk#start und civilDusk#end

		# Nacht-Ende nicht nach 22 Uhr
		if NachtBeginn.isAfter(Zeit2200Uhr):
			NachtBeginn = Zeit2200Uhr

		return NachtBeginn

# prüfen, ob es Tag oder Nacht ist
def fnNachtEnde():
		now =

		Zeit0600Uhr = now.withTimeAtStartOfDay.plusHours(5).plusMinutes(59).plusSeconds(30)		# 6 Uhr morgens (5:59:30)
		Sonnenaufgang = DateTime(ir.getItem("dtm_Astro_Sonnenaufgang").state).zonedDateTime.toInstant.toEpochMilli
		Differenz = Sonnenaufgang - now.millis
		NachtEnde = now.plusMillis(Differenz.intValue / 2)	# Mitte von civilDawn#start und civilDawn#end

		# Nacht-Ende nicht vor 6 Uhr
		if NachtEnde.isBefore(Zeit0600Uhr):
				NachtEnde = Zeit0600Uhr

		return int(NachtEnde.millis)

@rule("Test: Generisch")
@when("Item swi_Sys_Test changed to ON")
def TestRule(event):"Test Rule getriggert")

		# immer am Anfang, falls das Skript nicht zum Ende durchläuft...
		events.postUpdate("swi_Sys_Test", "OFF")

		# eigentlicher Code

		now =

		NachtBeginn = DateTime(fnNachtBeginn)
		NachNachtBeginn = now.isAfter(NachtBeginn.millis)

		NachtEnde = fnNachtEnde
		VorNachtEnde = now.isBefore(DateTime(NachtEnde).millis)

		if NachNachtBeginn or VorNachtEnde:
				events.postUpdate("swi_Astro_Nacht", "ON")"Es ist Nacht")
				events.postUpdate("swi_Astro_Nacht", "OFF")"Es ist Tag")

		# Ende vom eigentlichen Code"Test Rule beendet")

I haven’t written any rule in that way yet but could it be that the parenthesis ( and ) missing at the call of your functions and thus the object itself is copied to the variable instead of a call to the function.

Thanks a lot,
that was exactly the point!

1 Like