Announcement

Collapse
No announcement yet.

Arduino Script Testing. (Enigmatheatre)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • dhalsall
    replied
    Hi Greig,

    FYI, I managed to muddle through and modify the code for my final application:

    Code:
    Sub Main(parms As Object)
            Dim tempBOX As Integer
            Dim speedPCT As Integer
            Dim myDevCmd As String
            tempBOX = hs.DeviceValue(45)
            speedPCT = (tempBOX-25)*10
            myDevCmd = "Dim " & speedPCT & "%"
            hs.WriteLog("BOX Cool Down", " Box Temp: " & tempBOX &"C" & " Fan Percentage: " & speedPCT)
            CallCAPI(37, myDevCmd)
    End Sub
    
        Function CallCAPI(ByVal intDevRef As Integer, ByVal strDevCmd As String) As CAPIControlResponse
            CallCAPI = CAPIControlResponse.Indeterminate
            For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                If LCase(objCAPIControl.Label) = LCase(strDevCmd) Then
                    CallCAPI = hs.CAPIControlHandler(objCAPIControl)
                    Exit For
                End If
            Next
        End Function
    However, I have read your function over and over, and just don't get how it works! Mostly I'm sure because I have to improve my VB / scripting skills, but also, I find the references to these functions and methods in the HS3 scripting doc to be fairly vague. Is there a more in-depth resource to educate myself? Or is it just a lot of trial and error?

    Leave a comment:


  • dhalsall
    replied
    wow - thanks Greig.
    Hope you work well on 5hrs sleep (I'm the same).

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by dhalsall View Post
    DOAH!

    That's it... as usual, couldn't see the forest for the trees.

    Works as expected now - lol.

    Thanks for all you help Greig!

    I'll quietly attempt to learn the rest on my own - of course, this performance hasn't filled me with self confidence... but I'll keep pluggin' away.

    dave
    Good news. Glad we got there.
    I'm of to bed as it is 1.45am here and I am up at 7.[emoji17]

    Sent from my SM-G925F using Tapatalk

    Leave a comment:


  • dhalsall
    replied
    DOAH!

    That's it... as usual, couldn't see the forest for the trees.

    Works as expected now - lol.

    Thanks for all you help Greig!

    I'll quietly attempt to learn the rest on my own - of course, this performance hasn't filled me with self confidence... but I'll keep pluggin' away.

    dave

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by dhalsall View Post
    It is making me feel a bit better that you're finding it strange too

    tab below:
    In the event do you have a space between the comma and the dim? If so try removing it as it had to be exactly like the status pair.

    Greig.

    Sent from my SM-G925F using Tapatalk

    Leave a comment:


  • dhalsall
    replied
    It is making me feel a bit better that you're finding it strange too

    tab below:
    Attached Files

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by dhalsall View Post
    certainly...
    That also looks OK. Can you show me the graphics tab to.
    This is strange.

    Greig.

    Sent from my SM-G925F using Tapatalk

    Leave a comment:


  • dhalsall
    replied
    certainly...
    Attached Files

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by dhalsall View Post
    Hi Greig,

    Had to run to make dinner for the fam... See screen cap below.

    Regarding event aspect... probably better done as a complete script, but ultimately I'm looking to execute an event if a temperature is between X and Y, and if so, then use some simple arithmetic to take the temperature reading and create a percentage to output on this PWM line (which will spin up a fan to some range from slow to full).

    I realize I'll have to get better at my scripting abilities to get to that final destination. This effort was my attempt at hoping to understand how to control via script - and then I'd work backward to add in the other logic.
    Ok the event looks good.

    Can you show me a screen shot of the device advanced tab of device 37.

    Greig.

    Leave a comment:


  • dhalsall
    replied
    Hi Greig,

    Had to run to make dinner for the fam... See screen cap below.

    Regarding event aspect... probably better done as a complete script, but ultimately I'm looking to execute an event if a temperature is between X and Y, and if so, then use some simple arithmetic to take the temperature reading and create a percentage to output on this PWM line (which will spin up a fan to some range from slow to full).

    I realize I'll have to get better at my scripting abilities to get to that final destination. This effort was my attempt at hoping to understand how to control via script - and then I'd work backward to add in the other logic.
    Attached Files

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by dhalsall View Post
    Hi Greig,

    Thanks for all the effort! I was out this afternoon, but just got in and had a few minutes to try.

    I was intending on running it in an event, so I did create your example (cut and paste) - just changing the Device ID (37) and Dim value (70%).

    When the event runs, I get this in the log, however, no change to the actual output, nor any change in the Device Management view:



    I realize you literally have given me the answer - but I guess I'm more stupid than I had thought - lol.
    Ok that is strange

    Can you show me a screen shot of the device advanced tab.

    If you are using events then why not just set the device using control a device?

    Greig.

    Leave a comment:


  • dhalsall
    replied
    Hi Greig,

    Thanks for all the effort! I was out this afternoon, but just got in and had a few minutes to try.

    I was intending on running it in an event, so I did create your example (cut and paste) - just changing the Device ID (37) and Dim value (70%).

    When the event runs, I get this in the log, however, no change to the actual output, nor any change in the Device Management view:

    Jul-03 5:26:04 PM CallCAPI Device Reference: 37 strDevCmd: Dim 70%
    Jul-03 5:26:04 PM Event Running script in background: /home/pi/HomeSeer/scripts/CallCAPI.vb
    Jul-03 5:26:04 PM Event Event Trigger "Environmental Monitoring one-wire thermo test"
    I realize you literally have given me the answer - but I guess I'm more stupid than I had thought - lol.

    Leave a comment:


  • enigmatheatre
    replied
    OK I just thought that I guess you are not using events for this as you would just use the device in the event.

    in your script you are using just add the function at the bottom of your script after all your code.

    PHP Code:
        Function CallCAPI(ByVal intDevRef As IntegerByVal strDevCmd As String) As CAPIControlResponse
            hs
    .WriteLog("CallCAPI""Device Reference: " intDevRef " strDevCmd: " strDevCmd)
            
    CallCAPI CAPIControlResponse.Indeterminate
            
    For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                If 
    LCase(objCAPIControl.Label) = LCase(strDevCmdThen
                    CallCAPI 
    hs.CAPIControlHandler(objCAPIControl)
                    Exit For
                
    End If
            
    Next
        End 
    Function 
    Then in your script call the function using the line CallCAPI(1234, "Dim 40%")

    Greig.

    Leave a comment:


  • enigmatheatre
    replied
    OK I tested it and had forgotten you can not pass multiple params from and event so it is fixed in the last post.

    See picture for setup.
    Attached Files

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by dhalsall View Post
    Thanks Greig,

    I have to admit, my coding abilities are Kindergarten level at best.

    My head is about to explode trying to understand your code

    I was hoping to achieve the functionality in a single line of code. Reading other posts, I was thinking something like this might work (but of course it doesn't - and I'm just not smart enough yet to know why):

    &hs.CAPIControlHandler(&hs.CAPIGetSingleControl(37, false, "ON", false, true))

    I keep referencing the HomeSeer Scriping guide, but the lack of syntax / examples make my brain pain worse.

    Ultimately, this is a linux box and I'm not sure if it's an issue of C# vs vb.s that adding to my challenge. I did try the same line with &shs. .... ; but just different errors - lol.

    anyway, I don't expect you to waste your time teaching me - but if you have a cheat for doing this in one line, that would be wonderful!

    Ok if you are just looking to control a device but with CAPI add the following to a text file and call it CallCAPI.vb and add it to your scripts folder.

    PHP Code:
    Sub Main(ByVal params As String)

            
    Dim SplitParam() As String Split(params",")
            
    CallCAPI(SplitParam(0), SplitParam(1))

        
    End Sub

        
    Function CallCAPI(ByVal intDevRef As IntegerByVal strDevCmd As String) As CAPIControlResponse
            hs
    .WriteLog("CallCAPI""Device Reference: " intDevRef " strDevCmd: " strDevCmd)
            
    CallCAPI CAPIControlResponse.Indeterminate
            
    For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                If 
    LCase(objCAPIControl.Label) = LCase(strDevCmdThen
                    CallCAPI 
    hs.CAPIControlHandler(objCAPIControl)
                    Exit For
                
    End If
            
    Next
        End 
    Function 
    Now on the event call the script with the paramiters of the device reference and the text value you require.
    So for example the params would be 1234,Dim 40% to set the device 1234 to CAPI value Dim 40%

    Try and see how you get on.
    Ps this is untested code but if there are problems give me a shout.

    Greig.
    Last edited by enigmatheatre; July 3rd, 2016, 01:10 PM.

    Leave a comment:

Working...
X