Thing configuration from rules

This is the followup about how I solved it using rules.

As mentioned above, changing a thing’s config using the openHAB /things endpoint works like a charm. So that’s what I’ll do and thoroughly test now. See my real life example:

rules

rule "Work: Slow down Dimmer when adapting level"
  when Item work_lights changed to 0
    or Item work_lights changed from 0
  then
  var Number new_value
    if(work_lights.state > 0){
      logWarn("work.dimmer.adapter", "Dimmer level adaption. Setting to slow steps.")
      new_value = 100
    }
    else
    {
      logWarn("work.dimmer.adapter", "Dimmer off. Setting to fast steps.")
      new_value = 2
    }
  val String json = '{"config_6_2": ' + new_value + '}'
  logWarn("work.dimmer.adapter", json)
  sendHttpPutRequest("http://openhab:8080/rest/things/zwave:device:bridge:node18/config", "application/json", json)
end

This works well with the Fibaro Dimmer 2 FGD212. I just hope they save the settings in a flash memory and not an EEPROM which can only handle a few hundret writes. I’ll report back here if this breaks prematurely.

I’ll also let you hear from any new findings and problems - if any. Until then, I am open to any questions regarding this and wish you guys a nice day!

Hi @gersilex!
Thanks for sharing this! I guess this only works for things that are managed via paperUI? For things I’ve added manually, it won’t work?

I believe all UIs in openHAB work through REST calls. Open Paper UI and monitor the traffic (developer tools-network, or Fiddler)

That’s clear. My assumption is that manually added things, change settings via REST API does not work. (Because they are “unmanaged”)

This is correct. Just like when editing a Thing using the PaperUI or any other UI, as you and @luckymallari pointed out correctly, openHAB will deny changing the unmanaged thing and answer with an HTTP 409 “Conflict” error:

{
  "error": {
    "message": "Cannot update Thing zwave:device:bridge:node18 as it is not editable.",
    "http-code": 409
  }
}

Hi Gersilex,

I can see in your val string json you send a variable, do you know if its possible to send the value/state of a string item?

Thanks

Hi Chris,

If we use a PUT to send configuration parameters, which works fine, how do we delete those parameters? Sending fields blank does not remove them, and it errors.

If I send 1111 to a code, how would I remove 1111 from the REST API

Thanks
Kris

It’s not possible to remove parameters - they are always available. You can change the value only.

The answer is you send an empty string :slight_smile:

Not really - this will set the parameter to an empty string - it won’t remove it.

Well in any case, sending an empty string removed the values. Which is exactly what I needed.
You’re so literal Chris :smiley:

All good, values/parameters, different but same to a mug like me.

Absolutely. You can assign anything to new_value, not just integers.

      new_value = outside_lux.state

should work just fine.

1 Like

You can also configure Things using jython. This may also work for unmanaged Things, but I haven’t tried it.

try:
    from org.openhab.core.thing import ThingUID
except:
    from org.eclipse.smarthome.core.thing import ThingUID

then from within a rule, for example:

z_thing = things.get(ThingUID("zwave:device:741b4f3b:node10"))
z_thing.getConfiguration().put("config_6_1", someValue)
1 Like

Unmanaged Things are not configurable. BTW, I have a core.things module nearly ready to commit.

Good to know.

Looking forward to it.

Hi @DavidR,

thanks for the code!

Do you have to do something so that the thing is updating (it is a zwave sensor)?
I can set the config but there is no reaction. If I do it via Paper UI it seems that it is reacting.

Whether I do it by rule or PaperUI, it does the same. Have you tried turning on debug logging for Z-Wave? That may give some clues.

Hi Scott,

sorry to pull up such an old thread. Did you ever commit the core.things module? I’m looking for a jython example of how to create a thing and it’s channels. Would this module of yours solve this need?

Not yet, but it’s coming. I merged a number PRs last night, but there is a lot more to go.

OpenHAB Community,

I stumbled upon this thread looking for a “native” OpenHAB solution to being able to configure a Thing configuration parameter as part of a Rule.

The solution that I currently have it to use ZWaveJSUI and Zigbee2MQTT, and then you can literally map the MQTT topic to a channel and then to an Item.

So for example, I have an Inovelli LZW36 light/fan combo zwave switch connected to ZwaveJSUI, with this Generic MQTT Thing configuration:

Thing mqtt:topic:zwave01-nodeID_15 "F1_GuestRoom_Wall_Switch" (mqtt:broker:8fd56e1f3c) 
{
    Channels:
    Type dimmer : light_dimmer 
    [ 
        transformationPattern="JSONPATH:$.value",
        stateTopic="zwave01/nodeID_15/switch_multilevel/endpoint_1/currentValue", 
        commandTopic="zwave01/nodeID_15/switch_multilevel/endpoint_1/targetValue/set", 
        min=0, 
        max=100, 
        step=5 
    ]
    Type dimmer : fan_dimmer
    [ 
        transformationPattern="JSONPATH:$.value",
        stateTopic="zwave01/nodeID_15/switch_multilevel/endpoint_2/currentValue", 
        commandTopic="zwave01/nodeID_15/switch_multilevel/endpoint_2/targetValue/set", 
        min=0, 
        max=100, 
        step=5 
    ]
    Type number : kWh [stateTopic="zwave01/nodeID_15/meter/endpoint_0/value/65537", transformationPattern="JSONPATH:$.value"]
    Type number : watts [stateTopic="zwave01/nodeID_15/meter/endpoint_0/value/66049", transformationPattern="JSONPATH:$.value"]
    Type number : light-led-color 
    [
        stateTopic="zwave01/nodeID_15/configuration/endpoint_0/Light_LED_Indicator_Color", 
        transformationPattern="JSONPATH:$.value",
        commandTopic="zwave01/nodeID_15/configuration/endpoint_0/Light_LED_Indicator_Color/set"
    ]
}

This is my Item configuration:

// F1_GuestRoom
Group          gF1_GuestRoom_Wall_Switch   "Wall Switch"                              <light>         (F1_GuestRoom)                ["Equipment","WallSwitch"]     
Dimmer         F1_GuestRoom_Light          "Guest Room Light [%d]"                    <light>         (gF1_GuestRoom_Wall_Switch)   ["Lighting","Switchable","Point"]   {ga="Light", channel="mqtt:topic:zwave01-nodeID_15:light_dimmer"}                                              
Dimmer         F1_GuestRoom_Fan            "Guest Room Fan [%d]"                      <fan_ceiling>   (gF1_GuestRoom_Wall_Switch)   ["Switchable","Point"]              {ga="Fan" [ speeds="0=off:zero,33=low:one,66=medium:two,99=high:three", lang="en", ordered=true ], channel="mqtt:topic:zwave01-nodeID_15:fan_dimmer"}
Number:Energy  F1_GuestRoom_kWh            "Fan/Light Power Consumption [%.1f kWh]"   <Energy>        (gF1_GuestRoom_Wall_Switch)   ["Energy","Point","Measurement"]    {unit="kWh",channel="mqtt:topic:zwave01-nodeID_15:kWh"}
Number:Power   F1_GuestRoom_watts          "Fan/Light Wattage [%.1f W]"               <Energy>        (gF1_GuestRoom_Wall_Switch)   ["Energy","Point","Measurement"]    {unit="W",channel="mqtt:topic:zwave01-nodeID_15:watts"}
Number         F1_GuestRoom_LightLEDColor  "Guest Room Light Color [%d]"              <light>         (gF1_GuestRoom_Wall_Switch)   ["Point"]                           {channel="mqtt:topic:zwave01-nodeID_15:light-led-color"}

As you can see, you can map configuration endpoints just as easily as switch endpoints.

1 Like