Scripts for REST to *.(items|things)?

I’m about to endevour on moving to a build with jsonDB, before I bite the bullet, I’m wondering if anyone has created a converter to collect all their configs from a mixture of database/textual files. Using the REST interface, I can create the following bash script that moves all my items to one file. For this you’d need to install (apt-get) “jq”.

###Input

curl -s http://localhost:8080/rest/items/ | jq '.[] | .type + "\t" + .name
        + (if (.label | length) != 0 then
              ("\t\"" + .label + "\"")
           else "" end)
        + (if (.category | length) != 0 then
              ("\t<" + .category + ">")
           else "" end)
        + (if (.groupNames[0] | length) != 0 then
              ("\t(" + ((.groupNames | . ) | join(","))  + ")")
           else "" end)' --raw-output > fromDB.items

###Output

Number  Bedroom_MotionSensor_Luminance  "Luminance [%.1f lux]"  <Slider>
Switch  Bedroom_MotionSensor_Motion     "Motion [MAP(sensor.map):%s]"   <switch>        (Group_RestoreOnStartup)
Number  Bedroom_MotionSensor_Temperature        "Temperature [%.1f °C]" <Temperature>
Switch  Ben_Phone_Online        "Online"        <network>
Number  DiningRoom_DesktopPower_Current "Current [%.1f A]"      <Energy>
Number  DiningRoom_DesktopPower_EnergyConsumption       "Energy Consumption [%.1f kWh]" <Energy>        (Group_RestoreOnStartup)
Number  DiningRoom_DesktopPower_PowerConsumption        "Power Consumption [%.1f W]"    <Energy>
Number  DiningRoom_DesktopPower_PowerFactor     "Power Factor"  <Energy>
Switch  DiningRoom_DesktopPower_Switch  "Switch"        <Switch>        (Group_RestoreOnStartup)
[..etc]

This fails at doing two things

  1. Groups do not keep their function parameter. (Which could be solved using a nest if-then or maps above)
  2. Items lose their channel links.

Anyone have any additions? If not I can use the output of the above script as a guide to begin anew and I hope someone finds it just as helpful.

In another thread @hakan mentioned he is working on such a tool.

Perhaps the two of you can collaborate.

1 Like