[Release] HubDuino v1.1.4 - Hubitat to Arduino / ESP8266 / ESP32 / ThingShield Integration (ST_Anything)

community_app
community_driver

#164

Here you go... It only took a few minutes... :wink:

/**
 *  Child Servo
 *
 *  Copyright 2018 Daniel Ogorchock
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 *  Change History:
 *
 *    Date        Who            What
 *    ----        ---            ----
 *    2018-06-24  Dan Ogorchock  Original Creation
 *    2018-12-17  Dan Ogorchock  Enhanced for Blinds Control for user jayme9
 * 
 */
metadata {
	definition (name: "Child Servo", namespace: "ogiewon", author: "Dan Ogorchock") {
		capability "Switch Level"
		capability "Actuator"
		capability "Sensor"
		capability "Switch"

		attribute "lastUpdated", "String"
        attribute "angle", "number"
	}

	simulator {

	}

	tiles(scale: 2) {
		controlTile("levelSliderControl", "device.level", "slider", height: 2, width: 2, inactiveLabel: false) {
			state "level", action:"switch level.setLevel"
		}
 		valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "level", label:'${currentValue}%', unit:"%", backgroundColor:"#ffffff"
		}
 		valueTile("angle", "device.angle", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "angle", label:'${currentValue}°', unit:"degrees", backgroundColor:"#ffffff"
		}
 		valueTile("lastUpdated", "device.lastUpdated", inactiveLabel: false, decoration: "flat", width: 6, height: 2) {
    		state "default", label:'Last Updated ${currentValue}', backgroundColor:"#ffffff"
        }
       
		main(["angle"])
		details(["levelSliderControl", "level", "angle", "lastUpdated"])       
	}
}

def on() {
	setLevel(45)
}

def off() {
	setLevel(12)
}

def setLevel(value,duration=null) {
	log.debug "setLevel >> value: $value"
	def valueaux = value as Integer
	def level = Math.max(Math.min(valueaux, 99), 0)
    sendData("${level}")
	//sendEvent(name: "level", value: level, unit: "%")
}

def sendData(String value) {
    def name = device.deviceNetworkId.split("-")[-1]
    parent.sendData("${name} ${value}")  
}

def parse(String description) {
    log.debug "parse(${description}) called"
	def parts = description.split(" ")
    def name  = parts.length>0?parts[0].trim():null
    def value = parts.length>1?parts[1].trim():null
    if (name && value) {    
        // Update device
        sendEvent(name: "level", value: value)
        def angleValue = value.toFloat() * 1.81818
        angleValue = angleValue.round(2)
        sendEvent(name: "angle", value: angleValue)
        // Update lastUpdated date and time
        def nowDay = new Date().format("MMM dd", location.timeZone)
        def nowTime = new Date().format("h:mm a", location.timeZone)
        sendEvent(name: "lastUpdated", value: nowDay + " at " + nowTime, displayed: false)
    }
    else {
    	log.debug "Missing either name or value.  Cannot parse!"
    }
}

def installed() {
}

#165

lol thanks dan. You really are awesome!


#166

This works perfect!


#167

I ran into a problem. Not sure what happen. This was working great with google home. They were showing up as dimmers. I could say turn off/on. As of a couple days ago, they no longer show up in google home. If I re-add them in HE they stay on the list until I do a re-sync devices with google. This started around the same time of the HE firmware update. Not sure if it had anything to do with it. I tried testing with the child dimmer switch just to see if it would show up. Same problem. I am able to add it to the google home list in HE and update it. It stays in the list until I send a re sync devices, then it disappears.

This was all working great. I do not know what changed.


#168

try adding ' capability "Switch" 'to the Child Servo Driver to see if that helps.


#169

It already had it.


#170

I'm new to Google Home so this may be nonsense but I have noticed that Google relies on the device name more than Alexa. I say this because I added ten virtual switches, all identical driver wise, but 2 of them showed up as "lights" and were grouped together, while the others showed up as toggle switch icons. For the life of me I couldn't understand why until I noticed that the 2 in question had the word "light" in the label. I removed the word "light" and resynced. Everything now showed as toggle switches. ??? Strange to me but I guess I have to get used to how GH does things.

Maybe removing the word "blinds" may have an effect. Just a thought.


#171

Thanks, Ill try it when I get home.


#172

This had no effect. I tried renaming them light, bathroom light. Nothing.


#173

All - I have just updated my GitHub repository for the Parent and Child Groovy Drivers to include an automatic debug logging disable feature. Like most Hubitat Drivers, my drivers now include a new preference to Enable Debug Logging. This will enable log.debug statements for a period of 30 minutes. Afterwards, these debug.log statements will be disabled again automatically. This should really help make the "Past Logs" feature of Hubitat more useful as Past Logs will now be able to keep a longer history without all of the debug from my HubDuino drivers. Info, Warnings, and Errors will still be logged at all times. These are much less frequent.

Also, at the top of every Driver, I have now included the URL to the Raw Text of the driver on GutHub. This will make future driver updates easier as you will only need to copy that URL from within the edit driver page, and then paste it into the Import driver code feature, and then Save the new code.

Here is an example of what I am trying to explain above...


#174

Simple but effective.

Its the little things... Well done.


#175

Dan, I'm a new convert to Hubitat, and I have begun the process of moving devices over from SmartThings. My ST_Anything implementation of a hardwired security panel has been working smooth enough that I have not modified it in over a year. The move to Hubduino has me poking around looking for opportunities to improve it.

One task I am considering is improving the accuracy and consistency of the backup battery monitor which uses PS_Voltage. Using analogReference() seems like a good item to include in this effort. Have you considered adding an optional argument for selecting the reference voltage to be used?

Thanks for all you do to keep improving this code.

Jeff


#176

I seem to remember a couple other people asking about this months ago. Huh...wonder who that could be? :thinking::face_with_monocle:

Btw, I added modifying the on and off values via preferences rather than through the driver. I have several that are "open" to different value for my blinds. Also, it will report the correct switch state based on the preferences entered. For example if you want closed up to be off (99%, you can enter that) and get the switch to turn off by level set to 99 or switch off. :slight_smile: I'm learning!!!

/**
 *  Child Servo
 *
 *  Copyright 2018 Daniel Ogorchock
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 *  Change History:
 *
 *    Date        Who            What
 *    ----        ---            ----
 *    2018-06-24  Dan Ogorchock  Original Creation
 *    2018-12-17  Dan Ogorchock  Enhanced for Blinds Control for user jayme9
 * 
 */
metadata {
	definition (name: "Child Servo", namespace: "ogiewon", author: "Dan Ogorchock") {
		capability "Switch Level"
		capability "Actuator"
		capability "Sensor"
		capability "Switch"

		attribute "lastUpdated", "String"
        attribute "angle", "number"
	}

	simulator {

	}

	tiles(scale: 2) {
		controlTile("levelSliderControl", "device.level", "slider", height: 2, width: 2, inactiveLabel: false) {
			state "level", action:"switch level.setLevel"
		}
 		valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "level", label:'${currentValue}%', unit:"%", backgroundColor:"#ffffff"
		}
 		valueTile("angle", "device.angle", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
			state "angle", label:'${currentValue}°', unit:"degrees", backgroundColor:"#ffffff"
		}
 		valueTile("lastUpdated", "device.lastUpdated", inactiveLabel: false, decoration: "flat", width: 6, height: 2) {
    		state "default", label:'Last Updated ${currentValue}', backgroundColor:"#ffffff"
        }
       
		main(["angle"])
		details(["levelSliderControl", "level", "angle", "lastUpdated"])       
	}
}
preferences {
        input ("onvalue", "number", title: "On Percentage", required: false, defaultValue: 50, description: "Percentage that should be used for On command.")
        input ("offvalue", "number", title: "Off Percentage", required: false, defaultValue: 0, description: "Percentage that should be used for Off command.")
}

def on() {
	setLevel(onvalue)
}

def off() {
	setLevel(offvalue)
}

def setLevel(value,duration=null) {
	log.debug "setLevel >> value: $value"
	def valueaux = value as Integer
	def level = Math.max(Math.min(valueaux, 99), 0)
    sendData("${level}")
	//sendEvent(name: "level", value: level, unit: "%")
	if (level == offvalue){
		sendEvent(name: "switch", value: "off", isStateChange: true)}
	else{sendEvent(name: "switch", value: "on", isStateChange: true)}
}

def sendData(String value) {
    def name = device.deviceNetworkId.split("-")[-1]
    parent.sendData("${name} ${value}")  
}

def parse(String description) {
    log.debug "parse(${description}) called"
	def parts = description.split(" ")
    def name  = parts.length>0?parts[0].trim():null
    def value = parts.length>1?parts[1].trim():null
    if (name && value) {    
        // Update device
        sendEvent(name: "level", value: value)
        def angleValue = value.toFloat() * 1.81818
        angleValue = angleValue.round(2)
        sendEvent(name: "angle", value: angleValue)
        // Update lastUpdated date and time
        def nowDay = new Date().format("MMM dd", location.timeZone)
        def nowTime = new Date().format("h:mm a", location.timeZone)
        sendEvent(name: "lastUpdated", value: nowDay + " at " + nowTime, displayed: false)
    }
    else {
    	log.debug "Missing either name or value.  Cannot parse!"
    }
}

def installed() {
}

#177

Thanks Ryan. I have merged your changes into the current HubDuino Driver source code. The combined version is available at

https://raw.githubusercontent.com/DanielOgorchock/ST_Anything/master/HubDuino/Drivers/child-servo.groovy


#178

Very cool. I was thinking of changing it to retain the last level set when it's turned back on. And the switch function needs to be cleaned up so it doesn't report On again when it's already on...but it works for now. You did all the heavy lifting. :slight_smile:
If I do polish it more I'll just do a pull-request.


#179

Ooops! I just noticed you added some code the to setLevel() function. I have added that code to the GitHub version just now.


#180

Welcome to Hubitat! I am sure you’re going to like it.

If you’re a coder, you can modify the PS_Voltage class to include the optional argument and add the improvements to the code. I’d be happy to incorporate your improved version back into the main code base, assuming it is backward compatible.

If you’re not a coder, please point me to some example code that makes use of the reference voltage and I’ll try to get it added it.


#181

Thanks for updating the servo driver and Ryan for making those changes. I'm looking forward to moving my blinds off ST and finally unplugging it. :tada:


#182

Thanks @Ryan780 and @ogiewon This is a nice update for my blinds. And what ever was added allowed them to show back up in google home again!


#183

I'm a hobby coder (mechanical engineer by day). I will give it a go. If I fail, that will at least leave me in a position to explain what I am looking for. A little Arduino experimentation and data collection is in order first to be sure it is worth the trip.