This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Create visualisation from script
#1
Hello,

Is it possible to achieve such thing:

There would be a script, which would contain such information:


  1. Device name;
  2. Table headers (names);
  3. Table entries (names and if needed objects for control).
For example the device would be "Logicmachine5", table headers would be like "Input name" "Input state" "Output name" "Control output" "Comment" and table entries would be for example "IA" IA State" "OA" "OA State" "Not checked", so the whole table would look like this:

                        Logicmachine5
Input      Input State      Output      Control output     Comment
A            A State            A              On/Off                Not checked

And then if the script would run, it would create such a table in visualisation with all the objects, for this example it would have to create everything like this:
  • Device name and table headers as text labels;
  • Input entries as text labels;
  • Input states as "read-only" object states;
  • Output entries are text labels;
  • Control output entries are objects;
  • Comment entries are 250 string objects which can be modified from visualisation by end user.
All entries which are controllable or show states need to have the ability to assign them group address in the table creation script.

Is it possible to do this?

Maybe someone could give me a short example how this would work so I can build something out of it? The main part which I need is to know how can I create, if possible, visualisation elements from a script.

Thanks!
Reply
#2
This is possible but you will need to do direct db queries.

You can log all elements from a single plan (change 123 to your plan ID) like this:
Code:
id = 123
items = db:getall('SELECT * FROM visobjects WHERE floor=?', id)
log(items)

Then you can insert new elements into a plan. Data must be a table containing all the required field apart from id which must be nil to add a new element:
Code:
db:insert('visobjects', item)
Reply
#3
Ok, got it!

Thanks!

I'll let You know how it goes.
Reply
#4
Good night, I write this but the object is not created and when I consult the table it appears empty. Could you explain a little more?

Code:
db =insert('table', {object = 2305, name = 'Electro-válvula Corte Agua',
    params = {

    size = 12,

    bold = 0,

    italic = 0,

    underline = 0,

    width = 56,

    height = 56,

    icon_on = Electrovalvula_activada.png,

    icon_off = Electrovalvula.png,

    icon_touch = Electrovalvula.png,

    displaymode = icon-value,

    showcontrol = 0,

    update = false,

    widget = null,

    backdrop = 0},

   

   

    id = 42482,

    sortorder = 1,

  nobg = 1,

  statusobject = 2405,

  readonly= 0,

  locy = 107,

  locx= 35,

  floor = 851,

  notouch= 0

      })
Reply
#5
1. Check Errog log for errors because your code has correct syntax but running it will produce an error
2. Log the return value of the insert function call. Otherwise you won't know why insert does not happen
3. As I've already mentioned do not specify ID because it must be unique. The database will set it automatically if ID is not specified
4. type value is missing, this will cause the visualization to stop working completely

Try this:
Code:
require('json')

res, err = db:insert('visobjects', {
  object = 2305,
  statusobject = 2405,
  type = 0,
  floor = 851,
  locx = 35,
  locy = 107,
  nobg = 1,
  notouch = 0,
  readonly = 0,
  sortorder = 1,
  statusobject = 2405,
  name = 'Electro-válvula Corte Agua',
  params = json.encode({
    size = 12,
    bold = 0,
    italic = 0,
    underline = 0,
    width = 56,
    height = 56,
    icon_on = 'Electrovalvula_activada.png',
    icon_off = 'Electrovalvula.png',
    icon_touch = 'Electrovalvula.png',
    displaymode = 'icon-value',
    showcontrol = 0,
    update = false,
    widget = json.null,
    backdrop = 0
  }),
})
log(res, err)
Reply
#6
To much Thanks!!!! it works fine!!!
Reply
#7
I borrow this thread.

I have used the code above with success, but i have a problem using additional icons.  When making a log out of my sample floor, i get this sub table for the param section:

"icons_add":[{"min":0,
"max":20,
"icon":"arrow-up.svg"},
{"min":20,
"max":80,
"icon":"minus.svg"},
{"min":80,
"max":100,
"icon":"arrow-down-active.svg"}],


How do i write the section for the additional icons?
Reply
#8
(07.12.2020, 07:18)admin Wrote: 1. Check Errog log for errors because your code has correct syntax but running it will produce an error
2. Log the return value of the insert function call. Otherwise you won't know why insert does not happen
3. As I've already mentioned do not specify ID because it must be unique. The database will set it automatically if ID is not specified
4. type value is missing, this will cause the visualization to stop working completely

Try this:
Code:
require('json')

res, err = db:insert('visobjects', {
  object = 2305,
  statusobject = 2405,
  type = 0,
  floor = 851,
  locx = 35,
  locy = 107,
  nobg = 1,
  notouch = 0,
  readonly = 0,
  sortorder = 1,
  statusobject = 2405,
  name = 'Electro-válvula Corte Agua',
  params = json.encode({
    size = 12,
    bold = 0,
    italic = 0,
    underline = 0,
    width = 56,
    height = 56,
    icon_on = 'Electrovalvula_activada.png',
    icon_off = 'Electrovalvula.png',
    icon_touch = 'Electrovalvula.png',
    displaymode = 'icon-value',
    showcontrol = 0,
    update = false,
    widget = json.null,
    backdrop = 0
  }),
})
log(res, err)
Hello 
To run this code in different machine one should change
Name: which is the plan name?
icon_on, icon_off, icon_touch: script created Icon, and the icon name should be in my machine
object, statusobject! I don't understand what are these
what else should be changed?
regards
Reply
#9
(16.03.2021, 21:12)Håvard Fosså Wrote: How do i write the section for the additional icons?

Code:
icons_table = {
  { min = 1, max = 2, icon = "icon1.svg" },
  { min = 3, max = 4, icon = "icon2.svg" },
}

Add to params table:
Code:
icons_add = icons_table,



(17.03.2021, 08:45)khalil Wrote: Name: which is the plan name?
icon_on, icon_off, icon_touch: script created Icon, and the icon name should be in my machine
floor = 851, where 851 is the plan ID. For icons just specify the filename of each icon that is uploaded to Vis.graphics > Icons.
Reply
#10
(17.03.2021, 08:49)admin Wrote:
(16.03.2021, 21:12)Håvard Fosså Wrote: How do i write the section for the additional icons?

Code:
icons_table = {
  { min = 1, max = 2, icon = "icon1.svg" },
  { min = 3, max = 4, icon = "icon2.svg" },
}

Add to params table:
Code:
icons_add = icons_table,



(17.03.2021, 08:45)khalil Wrote: Name: which is the plan name?
icon_on, icon_off, icon_touch: script created Icon, and the icon name should be in my machine
floor = 851, where 851 is the plan ID. For icons just specify the filename of each icon that is uploaded to Vis.graphics > Icons.

thank you, admin 
what about 
  object = 2305,
  statusobject = 2405,
what are these 
see what I got

Attached Files Thumbnail(s)
   
Reply
#11
Main/status object address in a numeric form: X/Y/Z => X * 2048 + Y * 256 + Z
Reply
#12
(17.03.2021, 09:07)admin Wrote: Main/status object address in a numeric form: X/Y/Z => X * 2048 + Y * 256 + Z

thank you, admin 

I appreciate your help and patience
Reply
#13
(17.03.2021, 08:49)admin Wrote:
Code:
icons_table = {
  { min = 1, max = 2, icon = "icon1.svg" },
  { min = 3, max = 4, icon = "icon2.svg" },
}

Add to params table:
Code:
icons_add = icons_table,


Thank you!
Reply
#14
Hi,

How can I create text label?

An object is db:insert('visobjects', item) but a text?

Thanks
Reply
#15
Like this:
Code:
require('json')

res, err = db:insert('visobjects', {
  floor = 1,
  type = 6,
  params = json.encode({
    size = 72,
    color = '#ff9900',
    font = '',
    bold = 1,
    italic = 0,
    underline = 1
  }),
  name = 'label text',
  nobg = 1,
  locx = 35,
  locy = 107,
  cls = '',
})
Reply


Forum Jump: