Basic scripting

Discussion in 'C-Bus Automation Controllers' started by Russiops, Dec 14, 2018.

  1. Russiops

    Russiops

    Joined:
    Oct 26, 2017
    Messages:
    12
    Likes Received:
    0
    Location:
    Australia
    Hi guys,

    i'm trying to make a very basic script run on my 5500shac.
    Based on the idea by Damamax examples - minus the rasberry pi.


    i have a micro switch mounted to my garage door that is wired "open" when the door is open and connected to the digital input on the 5500shac. I want to get my Saturn zen edlt switches change background colour to red when the door is open. I have set up the zen switches and that side is working but my script is missing something. Do i need a script to start scripts or something silly.

    -- Read state of digital input
    value = ReadDigitalInput()
    if ReadDigitalInput() == open
    then
    -- Set lighting level of group 1 to 128 with ramp rate 4
    SetLightingLevel(3, 50, 4)
    else
    SetLightingLevel(3, 150, 4)
    end

    cheers JAson
     
    Russiops, Dec 14, 2018
    #1
  2. Russiops

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    275
    Likes Received:
    98
    Location:
    Sydney, NSW, Australia
    Put script in Residents and set seconds


    -- Read state of digital input
    value = ReadDigitalInput()
    if ReadDigitalInput() == true
    then
    -- Set lighting level of group 1 to 128 with ramp rate 4
    SetLightingLevel(3, 50, 4)
    else
    SetLightingLevel(3, 150, 4)
    end
     
    lcrowhurst, Dec 14, 2018
    #2
  3. Russiops

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    You need to define this as a resident script. You can then specify how often it will run (in seconds). For things like this every second is fine.

    Also, you read the input into a variable called 'value' but don't use it, because you read it again in the if statement. Delete the first line.

    Also 'open' and 'closed' are not defined (unless you define them somewhere!) so they are interpreted as 'false'. So it will work, but not as you think, and if you change the conditional to 'closed' it will still act as 'false'. You can use true or false but defining open as the correct one makes it more obvious what you are trying to do.

    try (as Resident Script)

    -- Read state of digital input
    open == true
    if ReadDigitalInput() == open
    then
    -- Set lighting level of group 1 to 128 with ramp rate 4 (this comment doesn't match the action!)
    SetLightingLevel(3, 50, 4)
    else
    SetLightingLevel(3, 150, 4)
    end


    Laurence types faster then me!
     
    Ashley, Dec 14, 2018
    #3
  4. Russiops

    Russiops

    Joined:
    Oct 26, 2017
    Messages:
    12
    Likes Received:
    0
    Location:
    Australia
    Hi Guys,

    you are both legends. Thanks for the prompt replies.

    You both put me on the right track. I had to change to false though for some reason. I got an error on line 2 Ashley, that i couldn't resolve. I would be interested in how to fix it though.

    The below works for me in the end.

    -- Read state of digital input
    value = ReadDigitalInput()
    if ReadDigitalInput() == false
    then
    -- Set lighting level of group 3 to 50 with ramp rate 4
    SetLightingLevel(3, 50, 4)
    else
    SetLightingLevel(3, 150, 4)
    end


    cheers Guys
     
    Russiops, Dec 15, 2018
    #4
  5. Russiops

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    Sorry, typo. Should have been "open = true" with a single =.

    Also, as I mentioned, you don't need the line "value = ReadDigitalInput()" . This just stores the digital input in a variable called "value" which you don't use as you read the input directly in the if statement.

    Either use:

    value = ReadDigitalInput()
    if value == false etc

    or

    if ReadDigitalInput() == false

    The first is only useful if you need to use "value" more than once in the script.
     
    Ashley, Dec 15, 2018
    #5
  6. Russiops

    Russiops

    Joined:
    Oct 26, 2017
    Messages:
    12
    Likes Received:
    0
    Location:
    Australia
    Thanks Ashley. Appreciate your help.
     
    Russiops, Dec 20, 2018
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.