Using getAstroSunriseStart action from astro1 binding in OH2

I’ve migrated from OH1 to OH2 using the text configuration approach. As far as I understand from other posts on this forum there are no actions in OH2, but you can use existing Actions from OH1 bindings. This however does not work for me using an action from the Astrology 1.x binding:

I’m using this code in my rules file (I’ve also included imports):

import java.util.concurrent.locks.ReentrantLock
import org.joda.time.*
import org.openhab.action.nma.internal.*
import org.eclipse.smarthome.core.*
import org.eclipse.smarthome.core.library.types.*
import org.eclipse.smarthome.core.persistence.*
import org.eclipse.smarthome.core.library.types.*
import org.eclipse.smarthome.action.astro.internal.*
import org.eclipse.smarthome.model.script.actions.*

rule "SystemStarted - Calculate some values"
when
  Item SystemStarted received command ON
then
  try {
    logInfo("SystemStarted", "Calculating astrology values")
    var Date current = now.toDate
    var DateTime currentDate = now.toDateTime
    var double lat = 52.0
    var double lon = 6.0
    var DateTimeType sunrise = new DateTimeType(getAstroSunriseStart(current, lat, lon))
    

Results in:
Rule 'SystemStarted - Calculate some values': An error occured during the script execution: The name 'getAstroSunriseStart(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>,<XFeatureCallImplCustom>)' cannot be resolved to an item or type.

Any idea on how to call Actions from the astro1 binding? The 1.x binding documentation has some clear examples (https://github.com/openhab/openhab/wiki/Actions#astro-actions), but the migration docs (http://docs.openhab.org/tutorials/migration) say nothing specific, other then to add the action to your addons.cfg, which looks like this:

# A comma-separated list of actions to install (e.g. "mail,pushover") action = nma,mail,astro1,mqtt,xbmc

and of course to change the imports, which I’ve done.

I don’t think the Astro actions will work under OH2 unless you do a number of things.

  1. First, there is no openhab-action-astro1. If it existed at all (which it doesn’t seem to), it would be openhab-action-astro. So remove astro1 from your action = line in addons.cfg.
  2. The 1.x Astro action bundle depends on the 1.x Astro binding bundle. You can get the JARs for both of them from here and dump them into your addons directory. Or just the action bundle and install the legacy 1.x Astro binding via the normal path.
  3. You will need to create an astro.cfg file in your conf/services directory as documented here for openhab.cfg, but without the astro: prefixes. I think just latitude and longitude are needed.
  4. I haven’t tested this, there might be problems, and it’s not currently expected to be supported.
  5. I wish there were an Astrology binding, bit sadly it’s only an Astronomy binding. :smile:

Thank you for your response.

This is what I’ve done:

  1. I’ve removed astro1 from my action = row in addons.cfg
  2. I’ve also removed astro1 from my binding = row in addons.cfg, as it claims it was already installed (org.apache.felix.fileinstall ] - A bundle with the same symbolic name (org.openhab.binding.astro) and version (1.9.0.201701030211) is already installed. Updating this bundle instead.)
  3. I already had a proper astro.cg in services/astro.cfg

Now it works :slight_smile: . The strange part is that other actions (nma, mail, mqtt, xbmc) work when they are added to action = row in services/addons.cfg, but for the astro action it requires me to add the binding and action jar’s manually. Thank you for your help!

1 Like

Careful if you have an action = or binding = line, as that means that only those actions or bindings will be installed. I know that the action JAR had to be added manually since no feature is currently defined for it, but I think you had two instances of the binding installed somehow, and however it gets installed (once) should be OK. The action JAR has code dependencies on the binding JAR, so that’s why it needs to be installed as well as the action JAR.

I will see if I can add a feature for the Astro action to the legacy features.