openhab-core: [automation] Binding actions cannot be configured by UIs

This is a follow-up issue of https://github.com/eclipse-archived/smarthome/issues/6602 as no solution has been implemented yet and we need to track it for OH3 release.

While implementing and testing my port of the Pushover add-on (https://github.com/openhab/openhab-addons/pull/8586) I again stumbled upon this missing feature. Currently it is not possible to configure inputs for Binding actions based on ThingActions. The annotated inputs are not visible in UIs.

image

    @RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription")
    public @ActionOutput(name = "sent", label = "@text/sendMessageActionOutputLabel", description = "@text/sendMessageActionOutputDescription", type = "java.lang.Boolean") Boolean sendHtmlMessage(
            @ActionInput(name = "message", label = "@text/sendMessageActionInputMessageLabel", description = "@text/sendMessageActionInputMessageDescription", type = "java.lang.String", required = true) String message,
            @ActionInput(name = "title", label = "@text/sendMessageActionInputTitleLabel", description = "@text/sendMessageActionInputTitleDescription", type = "java.lang.String") @Nullable String title) {
        logger.trace("ThingAction 'sendHtmlMessage' called with value(s): message='{}', title='{}'", message, title);
        return send(getDefaultPushoverMessageBuilder(message).withHtmlFormatting(), title);
    }

Internal automation actions like say or playSound define next to the inputs a list of configuration descriptions matching their inputs.

Conclusions of https://github.com/eclipse-archived/smarthome/issues/6602 are:

  • No short term solution to add support for input in the UIs. Proposal is to hide all ThingActions.
  • The is uncertainty about when to use inputs and when to use configuration descriptions (e.g. currently all existing core actions for NGRE defined them twice, an input and a related configuration).

Question is how to proceed? Should we hide all ThingActions in the near future? Or would it be an option to introduce a way to add configuration descriptions to ThingActions (e.g. by adding a new annotation for it)?

A previous private discussion between @kaikreuzer , @ghys , @openhab-5iver and myself resulted in the following brainstorming:

  • Displaying inputs along with config parameters should be doable to configure an action instance in a rule.

  • Apparently inputs have a type which is referenced in the API as a Java type (like java.lang.String or org.eclipse.smarthome.core.types.Command or org.eclipse.smarthome.core.events.Event), that’s a little bit different to the config parameters whose type is “TEXT” etc. Supporting anything other than primitive types in the UI could be tricky.

  • Given a module type like: image

    and a rule like: image

    I’m not sure how inputs are to be configured here, I suppose in the simplest case it’s something like below, with what the user configured in input boxes. But what if you want to use an output from another module?

"inputs": {
  "topic": "some/topic",
  "value": "somevalue"
}
  • It is also IMO not exactly clear which inputs are to be presented to the user and which are “technical” (for example “event” in GenericEventCondition or “input” in CompareCondition).
  • The ItemCommandAction module type has both a “command” input and a “command” config parameter described as “the default command to be sent if none is passed as an input value” - this would be confusing for users if both were displayed.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 55 (49 by maintainers)

Commits related to this issue

Most upvoted comments

I am counting 21 existing thing actions that cannot be run properly due to an unsupported output type:

  • astro: 4 => 3 QuantityType<?> + 1 ZonedDateTime
  • energidataservice: 3 => 2 Map<Instant, BigDecimal> + 1 BigDecimal
  • flume: 1 => 1 QuantityType<?>
  • modbus/helioseasycontrols: 4 => 4 List<String>
  • solarforecast: 5 => 3 QuantityType<?> + 2 Instant
  • visualcrossing: 2 => 2 WeatherResponse
  • dbquery: 2 => 2 ActionQueryResult

They should fail here: https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java#L119

@jlaur: as you are concerned with energidataservice, does it mean that these actions can be used inside a rule but not through the REST API ?

Here are the types found in existing thing action inputs that will be supported by UI:

  • String
  • Boolean
  • int
  • Integer
  • double
  • Double
  • long
  • Long
  • Number
  • DecimalType
  • QuantityType<Temperature>
  • QuantityType<Power>
  • QuantityType<Energy>
  • QuantityType<Time>
  • LocalDateTime
  • LocalDate
  • LocalTime
  • ZonedDateTime
  • Date
  • Instant
  • Duration

And those that will not be supported:

  • TimeUnit
  • UnitGroup
  • byte[]
  • List<String>
  • String…
  • List<Duration>
  • List<QuantityType<Power>>
  • Command
  • Map<String, @Nullable Object>
  • Object…

IMO we should cast the double received from the API to the required type

It is now done. String value is also accepted for numbers. LocalDate / LocalTime / LocalDateTime / ZonedDateTime types can now also be used by providing a string value respecting the appropriate format. I will document that. I will probably support few additional types to cover most of those currently used in existing thing actions.

I don’t think that I have to actually pass null as value through the API, I would think null is passed if the param is missing. But that is something we can easily try out …

Tested, you’re right. In case a parameter is not provided, null is passed as parameter to the method.

So, regarding invokation oif the action through the REST API, it works well for the following parameter types: boolean, Boolean, double, Double, String. Of course, for boolean and double, if you do not provide any value or if you provide null as value, there is an expected exception as null is considered. It fails for parameter of types int, Integer, long, Long, …

I have an idea how to fix that.

We would add a new REST API endpoint specific for UI usage.

In fact we can keep the existing API and just enrich ThingActionDTO.