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


Recommended Posts

Posted (edited)

When you use Supervisor scene and for some reason a scene stops responding and Supervisor restart just that scene, then if you for example have a timer started in a rule it will not continue from where it was.
Can that be solved somehow? Write every minute to a variable and if restart of scene rule looks at that variable and then continue from there?

 

Please login or register to see this code.

 

Edited by jompa68
Posted (edited)

@jgab

 

I have one suggestion - could be possible to develop function for sharing 

Please login or register to see this code.

with other scenes via publish/subscribe ?

 

so it means in one scene I want to define functions ie. for sonos and in other scenes I want to use new function for sonos as a standard ER rules.

 

Edited by petrkl12
Posted

@jgab

 

I had problem with one of my scene with a lot of triggers - scene was ended without any error message during every hours.

I have spent whole saturday with investigation why and reason is here:

Please login or register to see this code.

corrected:

Please login or register to see this code.

It looks that in some of cases setTimeout with time 0 doesn't call _poll and scene is ended ...

 

Could you please change your code? Thanks

 

  • Topic Author
  • Posted
    25 minutes ago, petrkl12 said:

    @jgab

     

    I had problem with one of my scene with a lot of triggers - scene was ended without any error message during every hours.

    I have spent whole saturday with investigation why and reason is here:

     

    It looks that in some of cases setTimeout with time 0 doesn't call _poll and scene is ended ...

     

    Could you please change your code? Thanks

     

    yes, I will add that change? I assume this on the HC2?

    Posted

    yes, there is only impact on hc2.

     

    Is it only one place where you can setTimeout to 0? Because it looks there will be some issue with fibaro implemenation of setTimeout ...

     

  • Topic Author
  • Posted
    15 minutes ago, petrkl12 said:

    yes, there is only impact on hc2.

     

    Is it only one place where you can setTimeout to 0? Because it looks there will be some issue with fibaro implemenation of setTimeout ...

     

     

    Maybe redefine setTimeout on the HC2?

    Please login or register to see this code.

     

  • Topic Author
  • Posted
    On 3/9/2019 at 8:27 AM, jompa68 said:

    When you use Supervisor scene and for some reason a scene stops responding and Supervisor restart just that scene, then if you for example have a timer started in a rule it will not continue from where it was.
    Can that be solved somehow? Write every minute to a variable and if restart of scene rule looks at that variable and then continue from there?

     

    Please login or register to see this code.

     

     

    Ok, you have a timer that should turn off the coffee machine after 45min. If the scene restarts you want it to continue where it left off. I.e. we need to remember the current time left in a global variable.

    This should work.

    Please login or register to see this code.

    We need a global 'myTimer' where we keep how many minutes left (we only count even minutes, but we could do %H.%M:%S)

    Whenever the status of 893 change we reset the variable to 45min. However when it turns on we start a timer that counts it down every minute. 

    rule(<...>).disable() starts a rule in disabled state.

    So, when the scene restarts it will use whatever value is in 'myTimer' as a starting value.

    Another trick, is that we at startup kick the 'for' rule, so that if 893:isOn we continue to run even if we don't get a new trigger.

    Posted (edited)

    Thanks @jgab

     

    anyone tried to publish a variable to a virtual variable?

    Please login or register to see this code.

    Correct

    Please login or register to see this code.

    But that gives me only the value from variable, how can also publish triggered variable name?

    Cannot find name in tojson(env)

    Please login or register to see this code.

     

    Edited by jompa68
    Posted (edited)
    3 hours ago, jgab said:

     

    Maybe redefine setTimeout on the HC2?

    Please login or register to see this code.

     

    It should be OK :)

     

    Edited by petrkl12
  • Topic Author
  • Posted
    2 hours ago, jompa68 said:

    Thanks @jgab

     

    anyone tried to publish a variable to a virtual variable?

    Please login or register to see this code.

    Correct

    Please login or register to see this code.

    But that gives me only the value from variable, how can also publish triggered variable name?

     

     

    Two ways, first:

    Please login or register to see this code.

    However, 

    In some cases you wouldn't need to wrap them in a VirtualVariables event. It's not always applicable but just as an illustration (can be done with 'property' event from devices too)

    Assume that the subscriber do

    Please login or register to see this code.

    and the publisher do

    Please login or register to see this code.

    What happens here is that the subscriber gets an event {type='global', name='UHASDarkness', value=<...>}

    and that looks exactly like a sourceTrigger for a normal fibaro global state change for the subscriber and its rules.

    What have we achieved? Well the subscriber can write rules involving the fibaro global 'UHASDarkness' without having to include it as a trigger in the scene header... because it gets the trigger sent to it from another scene ...

    The advantage with an event based model is that we can inject events that look like HC2's own source triggers and it look the same for the rules.

    Posted
    26 minutes ago, jgab said:

    What have we achieved? Well the subscriber can write rules involving the fibaro global 'UHASDarkness' without having to include it as a trigger in the scene header... because it gets the trigger sent to it from another scene ...

    The advantage with an event based model is that we can inject events that look like HC2's own source triggers and it look the same for the rules.

    Works perfect, and fast. Thank you :)

  • Topic Author
  • Posted

    I have pushed a new version of HC2.lua (v0.4) and a new version of EventRunner.lua (v2.0 B3)

    Many small fixes here and some major changes.

    First the way to send events from the emulator to HC2 or other external systems like node-red has changed. In the past when we did

    Please login or register to see this code.

    The event that was sent away had its ._from field set to -1, That way the HC2 or node_red new that the event should be sent back to the PC/Emulator. However now the emulator can run many scenes so we need to address what scene on the emulator we want to send to.

    The way I have solved it is that the ._from field is set to negative __fibaroSceneId, e.g. emulator scene 10 will be known as -10 in the HC2 and node-red. This allows HC2 and node-red to reply back by using the ._from field as the negative value tells them to send the event back to the emulator. Inside the emulator, scenes have their normal id's.

    In a scene you should always be able to reply to the ._from field in a remote event

    Please login or register to see this code.

    ...and the event should find its way back to the sender, wether it's on the HC2 or the emulator.

    So for most scenes this have no impact, but if you use node-red you have to update the "send event" part of the flow

    Please login or register to see this image.

    /monthly_2019_03/nr-6.png.208cd42c2b78f825a08f66794b0315bf.png" style="width:700px;height:auto;" alt="nr-6.png.208cd42c2b78f825a08f66794b0315bf.png" />

    The blue circled node is new and replaces the old ZBS node, and the red circled nodes need to be updated with the default sceneID these should sen to. If you want to send to local scene 10 in the emulator give value -10. If you want to send to scene 20 on the HC2, set it to 20.

    Please login or register to see this spoiler.

     

    Also, I have re-implemented the web server that reply on events sent to the emulator (node-red send to that server and HC2 scenes talking to the emulator send to this server, port 6872).

    It is much faster now and extensible so it should be possible to serve up a web GUI for some simple control or setting off triggers - but that's for the future. (maybe part of the VD emulator?)

    More of the pieces are in place now to solve pub/sub between emulator and HC2 but I'm not there yet.

    Posted

    Thanks for new version. In HC2 everything is OK,

    in ZBS it doesn't work for me - it looks that it doesn't read data from HC2 (remote=true). In previous version it works ...

     

     

     

    Posted

    also _SPEEDTIME = false it looks that speed is different than expected

     

  • Topic Author
  • Posted (edited)
    9 hours ago, petrkl12 said:

    Thanks for new version. In HC2 everything is OK,

    in ZBS it doesn't work for me - it looks that it doesn't read data from HC2 (remote=true). In previous version it works ...

     

    It hangs reading data or skip reading data? Could it be that it takes a very long time to read data from the HC2? Now I read all scenes and all lua code in the scenes, just to inspect the code to know if they are EventRunner scenes - maybe it's better to declare in emulators's main() what scenes on the HC2 we want to talk to.

    9 hours ago, petrkl12 said:

    also _SPEEDTIME = false it looks that speed is different than expected

    Yes, I noticed that too - will investigate.

    Pushed a version of HC2.lua that runs in "realtime" when _SPEEDTIME==false

     

    Pushed yet another version because I forgot a debug statement (HC2.lua 0.4  fix2)

    P.S Try to surf in to http://<emulator IP adress>:6872

     

    Edited by jgab
    Posted

    Good morning boys

    is this correct understanding?

    Please login or register to see this code.

     

    1 hour ago, jgab said:

    P.S Try to surf in to http://<emulator IP adress>:6872

    :D 

  • Topic Author
  • Posted
    16 minutes ago, jompa68 said:

    Good morning boys

    is this correct understanding?

    Please login or register to see this code.

     

    No, :isOn only works on numbers or table of numbers. Left hand here is an event (key value table).

    if when you receive a #VirtualSensor event want to test if the devise is on you can do

    #VirtualSensor{deviceID=‘$id’} & id:isOn => ...

     

    Posted (edited)
    2 hours ago, jgab said:

     

    It hangs reading data or skip reading data?

     

    I have problem with reading information from VDs. What I have to setup to read data from VDs directly from HC2?

     

    Tested :) (P.S Try to surf in to http://<emulator IP adress>:6872)

     

    Edited by petrkl12
  • Topic Author
  • Posted
    26 minutes ago, petrkl12 said:

    I have problem with reading information from VDs. What I have to setup to read data from VDs directly from HC2?

     

    There may have been a bug, pushed a new version of HC2.lua.

    The idea is that you in the beginning of HC2.lua (in it's main()) will setup what resources are local and what resources are remote (I stupidly called them "global", will change)

    Please login or register to see this code.

    If they are remote/global It should access them remote, if they are local they are just keeping a local state.

    What data you want to read? labels?

    Posted
    On ‎2‎/‎21‎/‎2019 at 12:01 PM, jgab said:

    Hi @jgab , in Lua functions can return multiple results, works even in fibaros implementation. Is it possible to call a function like below?

     function getsun(tid) 
        if (tid < 10) then 
          close_lux = 2500
          close_time = 120
          open_time = 600
        elseif (tid < 14) then 
          close_lux = 9000
          close_time = 300
          open_time = 1200
        elseif (tid < 15) then 
          close_lux = 6400
          close_time = 300
          open_time = 1200
        else 
          close_lux = 30000
          close_time = 60
          open_time = 600  
        end
        return close_lux, close_time, open_time
      end
      tiden=tonumber((os.date("%H"))) 
      x,y,z = getsun(tiden)  --does work ok
      fibaro:debug('x= '..x..'  y=  '..y..' z=  '..z)  --does work ok
      rule("(@sunrise+@@00:02) & (now >= 08:00) & (now <= sunset) => x,y,z=getsun(tiden); log('x= %s y= %s z= %s',x,y,z)")  --does not work

     

    Output from ZBS:

    [20:1][DEBUG] 16:49:29: Mon Mar 11: Loading rules
    [20:1][DEBUG] 16:49:29: x= 30000  y=  60 z=  600
    [20:1][DEBUG] 16:49:29: Mon Mar 11: Rule:1:(@sunrise+@@00:02) & (now >= 08:00) & (now <= sunset) => x,y,z=getsun(tiden); lo
    [20:1][DEBUG] 16:49:29: Mon Mar 11: 

     

    Join the conversation

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

    Guest
    Reply to this topic...

    ×   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...