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


  • 0

Sonos Alarm triggering a Scene in HC2?


Question

Posted

Hi,

 

Earlier I used OpenHAB with KNX, and I used a Sonos-plug-in that made it possible to trigger a scene/event in OpenHAB.

I want to use the Sonos Alarm to wake me up in the morning, and it would be great to have the alarm trigger a "Good morning-scene" as I did in OpenHAB.

 

Is this possible with VD in HC2?

 

Best regards

Kai

Recommended Posts

  • 0
Posted

Latest FW bring for us native plugin for Sonos

also you can try to find VD from KriKroff 

  • 0
  • Inquirer
  • Posted

    I'm using VD to cotrol my Sonos'es, but I don't find any possibility to use the VD to have an alarm trigger a scene......

    Is Sonos going to be native in HC2?

    • 0
    Posted

    A year later and I had the same question and figured it out. ?

     

    This is the Fibaro function to receive the alarms from your Sonos System:
     

    Please login or register to see this code.

    More information how I implemented it you can read at my

    Please login or register to see this link.

     article on my blog.

    • Like 1
    • 0
    Posted

    @Joep I am sorry.

    what is it?

     

        while b ~= nill do 
     
    • 0
    Posted

    @10der It's a while loop and it checks for a tag, if the regex doesn't find it the var is nill, so quit te loop. I'm not a programmer, if you can make it better, please, be my guest. This works for me. :)

    • 0
    Posted (edited)

    b will always be not equal to “nill”

     

    Or is Lua for HC2 that different from what I am used to with HC3? 
     

     

     

    Edited by SmartHomeEddy
    • Thanks 1
    • 0
    Posted (edited)

    i would say the first b check need extra line before

     

    Please login or register to see this image.

    /monthly_2020_09/image.png.3eeec9c4cb72fd60fef4edd5b1289678.png" />

     

     

    image.png.3da4131a0953147622229402eaeb988c.png

     

    but so far it works on HC3 (and now everyone know that i sleep till 11:00^^)

    Edited by tinman
    • 0
    Posted

    Strange, the code works on my HC2 as I described it on the blog.

    Maybe it's a HC3 thing. 

     

    To answer the b questions: ?

    I use the code if b ~= nill then within the loop because when the previous alarm was set, the loop enters another round and if no other alarm is found after that the var b is empty and the lua scene crashes. The line if b ~= nill then catches this.

     

    I had problems with parsing the XML with the parser code found on this forum, the HC2 showed with debug the correct XML, but I think it struggled with the SOAP XML envelope tags. Therefore I use this strange and dirty approach.

     

    Cool to see it works on the HC3. 

    • 0
    Posted

    btw, my Sonos displays ONCE, ON_, WEEKDAYS_, DAILY, WEEKENDS: depending on days combination, so consider adding check to your article/code. I did quick&dirty change to test:

     

    Please login or register to see this image.

    /monthly_2020_09/image.png.32537256e50f3141f3dc314a7c83a11f.png" />

     

    image.png.420271ac6d7793fd8c21e30c2379b4cd.png

     

     

    • 0
    Posted
    26 minutes ago, Joep said:

    I use the code if b ~= nill then within the loop because when the previous alarm was set, the loop enters another round and if no other alarm is found after that the var b is empty and the lua scene crashes. The line if b ~= nill then catches this.

    I read this topic with some amusement, please do not feel insulted, but you've probably written "a typo" and it happens to work and it is quite interesting. Your reasoning is sound and if you want reliable code this kind of tests (and proper handling) is important.

     

    My first reaction was what @10der already wrote, why nill, with double l?

     

    Please login or register to see this link.

     

    Nil is a type with a single value, nil, whose main property is to be different from any other value. As we have seen, a global variable has a nil value by default, before a first assignment, and you can assign nil to a global variable to delete it. Lua uses nil as a kind of non-value, to represent the absence of a useful value.

     

    Because you never assign any value to a variable called  nill, with double l - you are effectively compare with "nil". Let's test that idea with the "double ll version".

     

    Please login or register to see this code.

    You might think nill is special, but you can take an arbitrary non-existing variable to do this test!

    Please login or register to see this code.

     

    Advanced users on this forum may remember I often run some magic code before my real script, it is called "Check Global Leakage" and it is meant to detect reads and writes to global values, with some exceptions, and it helps to detect mixup of global and local variables. It catches this typo too...

     

    Please login or register to see this code.

    I can share this file but it only works if you develop "offline" because Fibaro Lua has removed some functions to make it work. Here you go.

     

    Please login or register to see this attachment.

     

    It is worth knowing this kind of error, because it can go unnoticed and cause hard to explain bugs.

    • Like 1
    • 0
    Posted
    25 minutes ago, petergebruers said:

    I read this topic with some amusement, please do not feel insulted, but you've probably written "a typo" and it happens to work and it is quite interesting.

     

    I post on the Internet to give something back to the community, I learned a lot and maybe other people learn or got inspired by something I write. When you post, you get reactions, and even more if your not the best in the programming scene. But your reaction is not insulting. You're explaining why you have (positive) criticism and I like that. Screaming without saying how to improve on the other hand not my thing, but that's not the case with your reply. ;)

     

    It is a typo, and after your post I realize it. I read over it every time. Stupid it works, I'm gonna change the code with your tips in mind and edit my blog. Thank you.

    • Thanks 1
    • 0
    Posted (edited)

    a some hints from XML guru  :)

     

    Please login or register to see this attachment.

     

    result

    image.png.30d87b688847290f84c6cebe6b481658.png

     

    Edited by 10der
    • Thanks 1
    • 0
    Posted

    add 

    parseXml

     

    add 

    getXmlPath

     

    now you can parse any XML :)

     

     

    • Like 1
    • 0
    Posted
    2 hours ago, 10der said:

    a some hints from XML guru  :)

     

    gr8!

     

    Luckily i have no idea about anything, so added your code into HC2 scene:

     

    image.png.c8c22c749a94643a3b4304e824de74a3.png

     

    and into HC3 scene:

     

    image.png.ffbc82898eb3ee5c768329f1abb2e7bc.png

     

     

     

    • 0
    Posted

    OK! just trying to check 

    • 0
    Posted

    like a charm :(

     

    image.png.2cc9454587661aa0d6773b1d234bae64.png

    Please login or register to see this attachment.

    • Thanks 2
    • 0
    Posted
    5 minutes ago, 10der said:

    OK! just trying to check 

     

    that should do the job, haven't tested deeper, just with the scene.

    Please login or register to see this code.

     

    • Thanks 1
    • 0
    Posted

    @tinman

    Please login or register to see this image.

    /monthly_2020_09/image.png.d609e2a1315a6c7237a19e3a64b32c13.png" />

    4 minutes ago, tinman said:

    with the scene.

    OMG!

    ok just will test

    • 0
    Posted

    the code you pasted was broken, or got changed within forum editor, this is why. Got it now?

     

    Please login or register to see this image.

    /monthly_2020_09/image.png.c5de5ffdc02f987850f71189e51519bc.png" />

    • 0
    Posted

    also

    OK

     

    Please login or register to see this attachment.

    attached as file

     

    Please login or register to see this attachment.

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