Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Question

Posted (edited)

In the absence of any offical Fibaro E learning on VDs can someone post a really simple VD to fill my knowledge vacum.

Something that shows the relationship between VD created button presses and their triggers ie button triggering scene, button changing state of variable

And changing state of modules  and variables and ther relationship to changed state of indication on VD buttons.

Ive tried looking at posted VDs but many get a bit complex for newbie.

A tutorial on this would be helpful for me and many others in the future.

Thanks

 

 

Edited by Jamie mccrostie

Recommended Posts

  • 0
Posted

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

  • 0
Posted (edited)
On 2/3/2017 at 9:00 PM, Jamie mccrostie said:

In the absence of any offical Fibaro E learning on VDs can someone post a really simple VD to fill my knowledge vacum.

Something that shows the relationship between VD created button presses and their triggers ie button triggering scene, button changing state of variable

And changing state of modules  and variables and ther relationship to changed state of indication on VD buttons.

Ive tried looking at posted VDs but many get a bit complex for newbie.

A tutorial on this would be helpful for me and many others in the future.

Thanks

 

 

 

Hi @Jamie mccrostie

 

I'll start the ball rolling on this

feel free to tell me if this is too simple or too complicated

 

Virtual Device 101

LABELS - enable the user to display a title and a value

BUTTONS - enable a user to execute an action, button can be manually pressed or through code. A VD can press one of its own buttons

MAIN LOOP -  Code here runs continuously in a loop

 

DEBUG - Main loop or button shows what is being echo'd back as it executes

 

Code snippets to help understand the two VD's I have attached

Treat these a building blocks to achieve various outcomes

 

Please login or register to see this code.

fibaro:log result data appears where the Running Instances : 1 is below

Please login or register to see this image.

/monthly_2017_02/Capture.PNG.58c92f9f3505bdb585c4b72bbcb0e91a.PNG" />

 

Please login or register to see this code.

Hope this helps and is on the right track

-f

 

 

 

 

 

Please login or register to see this attachment.

Please login or register to see this attachment.

Edited by AutoFrank
  • 0
Posted
17 hours ago, AutoFrank said:

-- Simple function. round a number (num) to a numnber of decimal places (idp) function roundit(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end

 

@Jamie mccrostie

 example of a part quote as per my PM to you

  • 0
Posted

Hi @Jamie mccrostie

 

from your PM I see where you're coming from 

In my code the jT.scene.XXXX was only an example

 

Let me put together a quick VD that may help

  • 0
Posted

@Jamie mccrostie

 

Try this 

 

Create two variables

Please login or register to see this attachment.

 

Import the following VD (attached to the post)

Please login or register to see this attachment.

The VD interacts with the two variables you created at the start

  • It sets a pump status to a global variable and displays it back, it reads it as a 0 or 1 and displays text "Pump is running" instead to make it easier to read
  • It also sets the last time the status was changed in a global variable and displays that as well
  • It displays the current time as a label
  • The main loop keep the labels up to date by reading either local variables (currenttime) or global variables
  • the email button takes some information and emails it to your admin account email address

I added the email part as a button because to have it trigger automatically when the status changes requires a little more code/complexity.

If you put it in the main loop it will be executed continuously so you would need some handling code to manage this. For now this should give you an understanding.

 

Pick your way through the code, I think its straightforward enough.

I did add some debug lines so you'll see more info in the debug screens

 

PRESS BUTTON

if you wanted to press one of the on the VD from another scene you need to know two things to use the following command

Please login or register to see this code.

The id of the virtual device (1870 above) and the button position (3 above)

The id can be derived from the browser url when you have either the General or Advanced tab open 

 

Please login or register to see this attachment.

In my screenshot above it 1870 but when you import it, the id will be different

 

The second is the button position

You need to count all elements in the VD

 

Please login or register to see this attachment.

 

so above buttons 4, 5 and 7 are valid PressButton actions

 

FIBARO:LOG

The fibaro.log command in the VD presents the information on the VD when looked at in the full list of devices

 

Please login or register to see this image.

/monthly_2017_02/Capture6.PNG.71dc090fe3f1a00888cea67cb587ee9c.PNG" alt="Capture6.PNG" />

 

Hopefully this will help your understanding

-f

 

 

 

 

 

 

 

Please login or register to see this attachment.

  • 0
  • Inquirer
  • Posted
    9 hours ago, AutoFrank said:

    f

     

    Thank you

    Taking away reference to HomeTable does take a layer of mist away from this.

    Ill dissect this this morning .

    Jamie

    • 0
  • Inquirer
  • Posted (edited)
    9 hours ago, AutoFrank said:

    f

     

    So how does pump relay update the global variable on the pumps condition im guessing i need to declear this somehow

    Pump running indicator relay id 265 ==0 then pumpStatus global =0

    how should iI do this part of the code?

    Thanks

    Also if you add 'reset' and 'pump fault' indication to the mix, is it best to just add another button, label and global 'pumpFault'  to mix?

     

    Edited by Jamie mccrostie
    • 0
    Posted
    25 minutes ago, Jamie mccrostie said:

    So how does pump relay update the global variable, im guessing i need to declear this somehow

    Pump running indicator relay id 265 ==0 then pumpStatus global =0

    how should iI do this part of the code?

     

    HI @Jamie mccrostie

     

    If you need the buttons to switch on the relay (pump)

    The you would modify the button code to 

     

    Please login or register to see this code.

    In the main loop add the following to read the status of the relay and set the global variable appropriately

    Please login or register to see this code.

    The existing code should then read the value of the global variable and update the labels

     

    I left of the pumpStatus out but if you want to track when the pump last changed state (like I had in the sample VD) then the code above should be

    Please login or register to see this code.

    Is this what you meant ?

     

     

     

    • 0
    Posted
    35 minutes ago, Jamie mccrostie said:

    Also if you add 'reset' and 'pump fault' indication to the mix, is it best to just add aother global 'pumpFault'  to mix?

     

    Yes - if you want to use this data outside the VD

    otherwise you could just keep track of the status of 'reset' and 'pump fault' within the VD

     

    The advantage of using a global variable to track something like  pumpFault is that you can trigger another scene by simply adding the global variable name to the header

    This other scene would looking something like

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    4 minutes ago, AutoFrank said:

    t

     

    Yes I recon you should add description re device  state change, changing global to your tutorial

    If you are a punter like me these snipits which are hard to find on forum or anywhere for that matter. 

    • 0
    Posted
    3 minutes ago, Jamie mccrostie said:

     

    Yes I recon you should add description re device  state change, changing global to your tutorial

    If you are a punter like me these snipits which are hard to find on forum or anywhere for that matter. 

     

    @Jamie mccrostie

     

    Good idea.. thanks

     

    Good luck with the coding :-)

     

    • 0
  • Inquirer
  • Posted
    14 minutes ago, AutoFrank said:

    if tonumber(fibaro:getValue(pumpRelay, "value"))) == 0 then fibaro:setGlobal("pumpStatus", "0") else fibaro:setGlobal("pumpStatus", "1") end

    So  'pumpRelay' bit would  be exchanged for relay id?

    • 0
    Posted
    7 minutes ago, Jamie mccrostie said:

    So  'pumpRelay' bit would  be exchanged for relay id?

     

    @Jamie mccrostie

     

    Correct ..

    a lot of people would keep the variable name like pumpRelay and declare the actual relay id in a local variable

    I think this is good practice as it makes the code easier to read especially when the lines of code go up (..and a good stepping stone should you move to using a HomeTable)

     

    so - with this in mind the code would look like

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted (edited)
    3 hours ago, AutoFrank said:

     

    @Jamie mccrostie

     

    Correct ..

    a lot of people would keep the variable name like pumpRelay and declare the actual relay id in a local variable

    I think this is good practice as it makes the code easier to read especially when the lines of code go up (..and a good stepping stone should you move to using a HomeTable)

     

    so - with this in mind the code would look like

     

    Please login or register to see this code.

     

     

    Hi Frank

    Spent some hours fiddling. Ive  adapted vfib a little and added some stuff, although It still doesn't work the mist is clearing.

     I could never get globals to change state either by your vd buttons or relay state if you could have a look at vfib attached would be great.

    There is a debug in main loop you will see and I don't get that either?

    Please login or register to see this attachment.

    Cheers muchly Jamie    (debug line 115:attempt to concatenrate local 'deviceId'(a nil value)

    Edited by Jamie mccrostie
    • 0
    Posted
    44 minutes ago, Jamie mccrostie said:

     

    Hi Frank

    Spent some hours fiddling. Ive  adapted vfib a little and added some stuff, although It still doesn't work the mist is clearing.

     I could never get globals to change state either by your vd buttons or relay state if you could have a look at vfib attached would be great.

    There is a debug in main loop you will see and I don't get that either?

    Please login or register to see this attachment.

    Cheers muchly Jamie    (debug line 115:attempt to concatenrate local 'deviceId'(a nil value)

    @Jamie mccrostie

     

    No worries, ...

    I'll take a look tomorrow

     

    Did you create the variables okay ? 

    • 0
  • Inquirer
  • Posted (edited)
    8 hours ago, AutoFrank said:

    Did you create the variables okay ?

    Please login or register to see this attachment.

    Hi

    So to follow up

         pump starts with start button

         Fault resets with reset button

         Global states dont change with either buttons or via relay states

         Hence Indication doesnt chage on vd

         Email doesnt send

         Prompt in vd doesnt show

         But debug buttons shows pump started/pump stopped

         My new fault label doesnt populate with fault or ready states

     

    One thing I was thinking lines 16 and 22 fibaro:get value where i am getting the relay states, should the 0 be  a off

    in the same way with fibro:call we turn relays/ switches on and off

    or when you put the tonumber in front does that change that

    so many questons...

    Thanks jamie

    Please login or register to see this attachment.

    Edited by Jamie mccrostie
    • 0
    Posted (edited)
    8 hours ago, Jamie mccrostie said:

    Please login or register to see this attachment.

     

    @Jamie mccrostie

     

    I got it running. small error in Line 22 (incorrect variable faultRelay instead of pumpFaultRelay)

    it should be  - 

    Please login or register to see this code.

    I'm not sure I understand how the overall solution concept is to work ...

    Could you explain the variables (pumpRunRelay, pumpFaultRelay, pumpFaultReset, pumpStartRelay)

    Are they all switches/relays ?

    Whats the difference between pumpRunRelay and pumpStartRelay ?

    Whats the purpose of FaultReset or FaultReset

     

    thanks

    f

     

     

     

     

     

    Quote

    Hi

    So to follow up

         pump starts with start button

         Fault resets with reset button

         Global states dont change with either buttons or via relay states

         Hence Indication doesnt chage on vd

         Email doesnt send

         Prompt in vd doesnt show

         But debug buttons shows pump started/pump stopped

         My new fault label doesnt populate with fault or ready states

     

    One thing I was thinking lines 16 and 22 fibaro:get value where i am getting the relay states, should the 0 be  a off

    in the same way with fibro:call we turn relays/ switches on and off

    or when you put the tonumber in front does that change that

    so many questons...

    Thanks jamie

    Please login or register to see this attachment.

     

    @Jamie mccrostie

     

     

    Edited by AutoFrank
    • 0
  • Inquirer
  • Posted (edited)
    4 hours ago, AutoFrank said:

    f

     

    Hi Auto Frank

     

    Thanks for looking and asking.  These fibaro 2 x double relays in pump panel

    The pumpstart relay, s1 load contacts connected in parallel start push button on pump control panel.

    The pump run relay, s2 switch contacts being switched by pump contactor  aux contact

    The Fault relay and Fault reset relay as above for fault indication and fault reset in pump fault circuit.

    So in the same way your grabbing the temps on your rack main loop im grabbing my fault and pump running indication.

    It doesnt have a stop button because the pump either starts remotely thru (tank fill) not fibaro, or high pressure cut out on irrigation (not fibaro)

    They all work now via fibaro switches in gui for remote start and indication, but thought since I had this set up at home  it was a good one to learn vd skills on. Does make sense?

    cheers

     

     

    Edited by Jamie mccrostie
    • 0
    Posted
    27 minutes ago, Jamie mccrostie said:

     

    Hi Auto Frank

     

    Thanks for looking and asking.  These fibaro 2 x double relays in pump panel

    The pumpstart relay, s1 load contacts connected in parallel start push button on pump control panel.

    The pump run relay, s2 switch contacts being switched by pump contactor  aux contact

    The Fault relay and Fault reset relay as above for fault indication and fault reset in pump fault circuit.

    So in the same way your grabbing the temps on your rack main loop im grabbing my fault and pump running indication.

    It doesnt have a stop button because the pump either starts remotely thru (tank fill) not fibaro, or high pressure cut out on irrigation (not fibaro)

    They all work now via fibaro switches in gui for remote start and indication, but thought since I had this set up at home  it was a good one to learn vd skills on. Does make sense?

    cheers

     

     

     

    @Jamie mccrostie

     

    yep, that makes sense..

    .. and I think it's always good to start on challenge that has a real life connection even if it won't end up being used

     

    Do you think you have a better idea of how the code and HC2 work now ?

     

    • 0
  • Inquirer
  • Posted

    Yes definatly not just with vds but adds to whole concept.

    I didnt add that the pump start  relay is set to momentary setting in the pump start circuit thats why i couldnt use same relay for run indication.

     

    But anyway I still cant get the globals to change state. Can you see anything obvious on my attachment? As i said in otherpost your orignal vd buttons dont change globas either?

    cheers

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...