Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to import rule templates (create many rules from a single import file) #75

Open
raintonr opened this issue Oct 6, 2022 · 8 comments

Comments

@raintonr
Copy link
Contributor

raintonr commented Oct 6, 2022

See UncleSamSwiss/ioBroker.loxone#337 (comment)

Many device statistics can be read from a Loxone miniserver, which are read via HTTP requests to the device. Initially one might think reading these statistics is the job of the module specific for that device (the Loxone Miniserver) but it would be practically duplicating the work of this parser module sooooooooo...

It might be nice that if after someone spent quite some time defining all the HTTP requests necessary to fetch the full set of statistics (in the parser configuration page), that they could export that configuration for that device.

However, one would obviously need a method to select which of the items in the parser configuration they wanted to export into a template and also which of the parts of any URL are variables (in the case of Loxone, the host name and credentials for 'privileged' statistics). In this case, I think as a first step it could be cumbersome to try and create a template from within the parser admin interface and a better solution would be to focus on importing a hand crafted template file (in JSON format for example). In this way, people could create and share such files to fetch numerous items from multiple services - it clearly would not be limited to a Loxone Miniserver.

However, taking a couple of items from the Loxone Miniserver as an example, I imagine such a template file could be along the lines of (with many more entries of course):

{
   "variables":[
      "host",
      "user",
      "pass"
   ],
   "items":[
      {
         "name":"$host.dev_sps_state",
         "URL":"http://$host/dev/sps/state",
         "regexp":"/value=\"(\\d*)\"/",
         "item":0,
         "role":"value",
         "type":"number",
         "interval":60000
      },
      {
         "name":"$host.dev_lan_txp",
         "URL":"http://$user:$pass@$host/dev/lan/txp",
         "regexp":"/value=\"(\\d*)\"/",
         "item":0,
         "role":"value",
         "type":"number",
         "interval":5000
      }
   ]
}

Variables would need to be requested at time of import, then all the parser rules would be created as a result.

@Apollon77
Copy link
Collaborator

In fact the adapter confog page should have a "export" button upper right, or not? If yes you coukld download the config, add the stuff you need (yes without such variables) and import that again

@raintonr
Copy link
Contributor Author

raintonr commented Oct 7, 2022

... you coukld download the config, add the stuff you need (yes without such variables) and import that again

That would be go most of the way there.

But... if rules are supposed to be included in such exports that appears broken. For example, I created a rule & downloaded the config but the rule just isn't shown in there :(

@Apollon77
Copy link
Collaborator

Ahhh right ... the rules are stored as objects ... then your thing might be even easier ... just create objects with the correct native part

@raintonr
Copy link
Contributor Author

raintonr commented Oct 7, 2022

Ermmmmm? Do you have an example? How would one import many objects in one go?

@Apollon77
Copy link
Collaborator

Check the objects created in your installations in parser.0.* ... these ARE the objects!

e.g.

{
  "_id": "parser.0.Donnerwetter.Knielingen.Niederschlag.Tag1",
  "common": {
    "name": "Donnerwetter.Knielingen.Niederschlag.Tag1",
    "write": false,
    "read": true,
    "unit": "l/m2",
    "type": "number",
    "role": "value"
    }
  },
  "native": {
    "link": "http://www.donnerwetter.de/agrar/region.mv?lid=XXXXX",
    "regex": "<strong>Niederschlag<\\/strong><\\/td>[^>]*\">([0-9.]+) L\\/m[^\"]+[^>]*\">[0-9.]+ L\\/m[^\"]+[^>]*\">[0-9.]+ L\\/m[^\"]+[^>]*\">[0-9.]+ L\\/m",
    "interval": "900000",
    "factor": 1,
    "offset": 0,
    "substitute": "-1",
    "comma": false,
    "item": 0,
    "substituteOld": true
  },
  "type": "state",
  "acl": {
    "object": 1636,
    "state": 1636,
    "owner": "system.user.admin",
    "ownerGroup": "system.group.administrator"
  },
  "from": "system.adapter.admin.0",
  "ts": 1553291085457
}

@raintonr
Copy link
Contributor Author

raintonr commented Oct 7, 2022

Yeah, so are you telling me I would have to create them one by one? That would be very painful.

@Apollon77
Copy link
Collaborator

Apollon77 commented Oct 7, 2022

You ever heared of the javascript Adapter? You can enable them to have setObject allowed ... and then use a loop... come on. ;-)
Or build a JSON and import the objects into Admin!! Also an option (as alternatives for the import)

@raintonr
Copy link
Contributor Author

raintonr commented Oct 8, 2022

Works, but not very user friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants