CutomDTH help to set custom parameters


#1

Need help from a dth guru.

I have a device handler that I am trying to get working.

You can set alarm time from the device in the settings and webcore will read it as one of the attributes. However I would like to be able to set the alarm time from webcore and the dth change the alarm time in the device. I just can’t figure out how to pass information to the dth and have the dth apply what it gets.

I know I would need the use of a custom command and a custom parameter. But not sure how to handle that info.

Here is what I am working with so far

/**

  • This is copied directly from the Z-wave switch with power metering from SmartThings, i added a Image Capture

  • capability just to be able to send a string to webcore, the string is the departure time which represent

  • when you are leaving your home so the switch turns on a couple of hours before if you have plugged in

  • your engine heater cable. All rules are set in webcore though. This just provides an easy way of setting

  • a departure time.
    */

     metadata {
     	definition (name: "Alarm On/Off Button Tile", namespace: "Alarm", author: "adapted from 949BFN") {
     		capability "Actuator"
     		capability "Switch"
     		capability "Sensor"
             capability "Image Capture"
             attribute "alarm","string"
             command "changeAlarmTime"
         }
         preferences {
         input name: "timer", type: "time", title: "Alarm Time", description: "Enter Time", required: false
     	}
     	// simulator metadata
     	simulator {
     		}
     	// UI tile definitions
     	tiles {
     		standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
     			state "off", label: 'OFF', action: "switch.off", icon: "st.Health & Wellness.health7", backgroundColor: "#ffffff",nextState:"on"
     			state "on", label: 'On', action: "switch.off", icon: "st.Health & Wellness.health7", backgroundColor: "#00A0DC",nextState:"off"
     		}
     		valueTile("alarm", "device.alarm") {
     			state "default", label:'Alarm: ${currentValue}',backgroundColor: "#00A0DC"
     		}
     		main(["button","alarm"])
     		details(["button","alarm"])
     	}
     }
     def parse() {
     }
     def updated() {
            def time = timer.substring(11,16)
             def tz = location.timeZone
     		def schedTime = timeToday(timer, tz)
     		//def ntime = schedTime.format("H",tz)
     		//def min = schedTime.format("m",tz)
             //def newtime = schedTime.format('HH:mm:ss', tz).toString()
         if(timer) {
         		log.debug "Alarm time set to: $timer"
                 sendEvent("name":"image", "value":schedTime)
                 sendEvent("name":"alarm", "value":time)
         } else {
         		log.debug "No departure time is set"
         		}
     }
     def on(){
     sendEvent(name:"switch",value:"on")
     }
     def off(){
     sendEvent(name:"switch",value:"off")
     }

#2

You can change physical device parameters using custom commands but it will never update the displayed value in the settings view I’m afraid… that can only be done manually via the app :sob:

By alarm, do you mean alarm clock?


#3

Yes, I think. If you look at that device handler I posted. There is a place that allows you to input the alarm time.
preferences {
input name: “timer”, type: “time”, title: “Alarm Time”, description: “Enter Time”, required: false
}
And then there is then there is the
def schedTime = timeToday(timer, tz)

So in one of the tiles it displays the:
valueTile(“alarm”, “device.alarm”) {
state “default”, label:‘Alarm: ${currentValue}’,backgroundColor: “#00A0DC
}

Webcore can pull that info. I want to be able to set that infor from webcore without having to do it from the device in ST

I may be looking at the wrong lines to do it. But that is what I am trying to do.


#4

My point is you can’t change a value displayed in the preferences page without going into the preference page.

You can set a value in a tile, but tiles can’t display a time (unless you rig it with two seperate dimmer / thermostat tiles (one for hours and one for minutes)), which would involve assembling and disassembling the time in webCoRE, and sending two custom commands.

Even if you can display the time this way in a tile, the preferences page and preference value will not change unless the user clicks the cog and changes it.


#5

Dang it, I New I was in over my head…


#6

I’ve been looking for a DTH like this for a while so will have a tinker with it tomorrow sometime.


#7

What my ultimate goal was to be able to this:

  1. Tell google home “ ok google set alarm for tomorrow morning at 7:00 A.M.”
    1a. Have google set a calendar event for alarm time
  2. Use that alarm dth to set the time to desired time.
  3. Use webcore to run a piston based off that time and trigger at desired time
  4. Use my sonos speaker to play a specified sound file at desired time.

All of this without having to interact with webcore or device (hands free)

I was going to use google home to setup an event on google calendar for desired time
Then use gcal search smart app to parse the info from calendar and set the alarm time in device handler
Then have the dth as the trigger for my sonos play sound piston.

That WAS the goal.


#8

ok… I’ve fixed up the DTH and have this working now as a simple alarm clock… don’t have Google Home but I’ve fixed the switch on/off states which were setup wrong so should work for on/off at least.

Setting alarm time and google spreadsheets from Google Home may be a bit more tricky… let us know how you get on!

metadata {
 	definition (name: "Alarm On/Off Button Tile", namespace: "Alarm", author: "Robin") {
 		capability "Actuator"
 		capability "Switch"
 		capability "Sensor"
        attribute "alarm","string"
        command "changeAlarmTime"
     }
     preferences {
     input name: "timer", type: "time", title: "Alarm Time", description: "Enter Time", required: false
 	}
 	// UI tile definitions
 	tiles {
 		multiAttributeTile(name:"switch", type: "generic", width: 6, height: 4, canChangeIcon: true, canChangeBackground: false){
			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
 			attributeState "off", label: 'off', action: "switch.on", icon: "st.Health & Wellness.health7", backgroundColor: "#ffffff"
 			attributeState "on", label: 'on', action: "switch.off", icon: "st.Health & Wellness.health7", backgroundColor: "#00A0DC"
 		}
        }
 		valueTile("alarm", "device.alarm", width: 6, height: 3) {
 			state "default", label:'${currentValue}',backgroundColor: "#00A0DC"
 		}
 		main(["switch","alarm"])
 		details(["switch","alarm"])
 	}
 }
 def parse() {
 }
 def updated() {
        def time = timer.substring(11,16)
         def tz = location.timeZone
 		def schedTime = time //Today(timer, tz)
 		//def ntime = schedTime.format("H",tz)
 		//def min = schedTime.format("m",tz)
         //def newtime = schedTime.format('HH:mm:ss', tz).toString()
     if(timer) {
     		log.debug "Alarm time set to: $timer"
             sendEvent("name":"image", "value":schedTime)
             sendEvent("name":"alarm", "value":time)
     } else {
     		log.debug "No departure time is set"
     		}
 }
 def on(){
 sendEvent(name:"switch",value:"on")
 }
 def off(){
 sendEvent(name:"switch",value:"off")
 } 
 def changeAlarmTime(paramTime) {
    sendEvent("name":"alarm", "value":paramTime)
}

Sounding alarm clock at the set time:

Setting alarm time (can also be done from the device preferences page as before):


#9

Thank you so much for your time on this. Now to integrate it with the gCal Search smart app to get alarm time to populate. There goes my evening :nerd_face:


#10

#11

@Robin This is way better than what I was asking for help with, thank you.

Now what I have found out is I can turn on the overall alarm or off by just saying “ok google turn off test alarm”. Where I named the device “ test alarm”

But, to take it one step further, is there a way to expose the days of the week to turn those off?

Something lik you can do with a dimmer switch only for the days.
Just a thought, “ ok google, turn on test alarm Monday” and it would turn Monday on or off?

I know I am pushing the limits, just trying help make this even better.

I know, give them an inch and they will ask for a yard!

Great job, I like as is, though


#12

The days of the week are as exposed as they can be… webCoRE can control them.

Unfortunately, most smartapps, Alexa, and by the sounds of it GH, can’t access added switches, just the primary one.

If I was doing this with Alexa I would setup 7 routines in ST, each triggering webCoRE to toggle a switch, and then call the routines via Alexa.