Announcement

Collapse
No announcement yet.

replace not working

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

    replace not working

    I am trying to eliminate the word 'Reminder' from the body of a sms message before sending it to a TTS command. But is still speaking the full message

    Code:
    Sub Main(parm as object)
     Dim reminder as String
     reminder = "$$DSR:331:"
     reminder = reminder.Replace("Reminder","")
     hs.speak(reminder,True, "$SONOS$KitchenTTS$")
     
    End Sub
    The sms body (in "$$DSR:331:") is 'Reminder this is a test message'

    and I want the result to be a TTS with 'this is a test message'

    #2
    Replacement variables do not work inside scripts. So reminder = "$$DSR:331:" returns exactly "$$DSR:331:". You need to use scripting commands to retrieve what you need.

    Cheers
    Al

    PS Looks like you are trying to get the status from a device. The scripting command for that is hs.CAPIGetStatus. The HS3 help file has a good example on how to use it.
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    Comment


      #3
      Originally posted by sparkman View Post
      Replacement variables do not work inside scripts. So reminder = "$$DSR:331:" returns exactly "$$DSR:331:". You need to use scripting commands to retrieve what you need.

      Cheers
      Al

      PS Looks like you are trying to get the status from a device. The scripting command for that is hs.CAPIGetStatus. The HS3 help file has a good example on how to use it.
      Sorry my knowledge of scripting is very limited. I am using below in another script, and that WORKS FINE

      Code:
       Try
      energy_name = ""
      energystr = ""
       
       for each devt as string in array_energy 
                         watts = hs.DeviceValueByNameEx(devt)
                   
               If watts > 0 
                         energy_name = devt
                         energy_name = devt.Replace("Watts","")
      This is only a part of the script, which I tried to adapt. The "$$DSR:331:" is from the SMS plugin, which hold the sms message body.

      Comment


        #4
        There's nothing wrong with the replace function. The issue is the replacement variable "$$DSR:331:" which won't get replaced with the status of device 331 within the script. As per my first post, you would have to use the hs.CAPIGetStatus command to retrieve the status of device 331.

        This should work:
        Code:
        Sub Main(parm as object)
        	Dim reminder as String
        	Dim CS As Object 
        	CS = hs.CAPIGetStatus(331)
        	reminder = CS.Status
        	reminder = reminder.Replace("Reminder","")
        	hs.speak(reminder,True, "$SONOS$KitchenTTS$")
        End Sub
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          #5
          Originally posted by sparkman View Post
          There's nothing wrong with the replace function. The issue is the replacement variable "$$DSR:331:" which won't get replaced with the status of device 331 within the script. As per my first post, you would have to use the hs.CAPIGetStatus command to retrieve the status of device 331.

          This should work:
          Code:
          Sub Main(parm as object)
              Dim reminder as String
              Dim CS As Object 
              CS = hs.CAPIGetStatus(331)
              reminder = CS.Status
              reminder = reminder.Replace("Reminder","")
              hs.speak(reminder,True, "$SONOS$KitchenTTS$")
          End Sub
          Ok now I understand what you meant. And its working. Thanks

          Comment

          Working...
          X