0
Answered: Discussion Open

Changing units of Voltage Measurement Tile

JBoer 6 years ago in Things & Capabilities / Non-"Works With SmartThings" devices updated by Terry (ActionTiles) (Co-Founder) 6 years ago 3

Hi All,


I have a voltage sensor in ST actually measuring Water Tank levels and so was wanting to be able to have a % symbol rather than the 'V' units on the tile. I do have % showing in ST but I presume AT doesn't pull the unit from ST.


So is there a way for me to change the measurement unit symbol for the Voltage Sensor tile?


Thanks

Answered: Discussion Open

Hi J,


The "units" parameter in SmartThings Events isn't used consistently by Device Type Handlers, so ActionTiles must ignore it.


You can change your DTH to make a more meaningful claim of Capability "Battery" instead of Voltage Measurement. Battery reports a single integer attribute "battery" of value 0 to 100 (representing percent). http://docs.smartthings.com/en/latest/capabilities-reference.html#battery


The ActionTiles "Battery Tile" will then be applicable to show your Water Tank level...


Make sense?


...Terry.

Thank you for your reply however I am not having much success with this as I am using ST_Anything for my sensors and so it is not as straight forward as I hoped. I have been able to change the Capability to 'Battery' but am not being able to get the values through.


If you have the time would you be able to show me what I need to change in Dan's code to get it to show as a battery in ActionTiles?



/**
 *  Child Voltage Sensor
 *
 *  Copyright 2017 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
 *    ----        ---            ----
 *    2017-04-19  Dan Ogorchock  Original Creation
 *    2017-08-23  Allan (vseven) Added a generateEvent routine that gets info from the parent device.  This routine runs each time the value is updated which can lead to other modifications of the device.
 *    2018-06-02  Dan Ogorchock  Revised/Simplified for Hubitat Composite Driver Model
 *
 *
 */
metadata {
    definition (name: "Child Voltage Sensor", namespace: "ogiewon", author: "Daniel Ogorchock") {
        capability "Voltage Measurement"
        capability "Sensor"         attribute "lastUpdated", "String"
    }
        
    tiles(scale: 2) {
        multiAttributeTile(name: "voltage", type: "generic", width: 6, height: 4, canChangeIcon: true) {
            tileAttribute("device.voltage", key: "PRIMARY_CONTROL") {
                attributeState("voltage", label: '${currentValue}%', unit: "%", defaultState: true)
            }
             tileAttribute("device.lastUpdated", key: "SECONDARY_CONTROL") {
                    attributeState("default", label:'    Last updated ${currentValue}',icon: "st.Health & Wellness.health9")
            }
        }
    }
} 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: name, value: value)
        // 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() {
}


Mostly you just need to change "Voltage Measurement" to "Battery" and "voltage" to "battery"; but that doesn't cover the parse() method.


The parse() method is grabbing the keyword "voltage" (I think?) from the message from the device, and using that to set the name.


So my untested guess as to the code:


metadata {
    definition (name: "Child Voltage Sensor", namespace: "ogiewon", author: "Daniel Ogorchock") {
        capability "Battery"
        capability "Sensor"
        attribute "lastUpdated", "String"
    }
        
    tiles(scale: 2) {
        multiAttributeTile(name: "battery", type: "generic", width: 6, height: 4, canChangeIcon: true) {
            tileAttribute("device.battery", key: "PRIMARY_CONTROL") {
                attributeState("battery", label: '${currentValue}%', unit: "%", defaultState: true)
            }
             tileAttribute("device.lastUpdated", key: "SECONDARY_CONTROL") {
                    attributeState("default", label:'    Last updated ${currentValue}',icon: "st.Health & Wellness.health9")
            }
        }
    }
}
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
        if ( name == "voltage" ) { name = "battery" }
        sendEvent(name: name, value: value)
        // 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!"
    }
}


If this doesn't work, you can contact us for paid screen sharing session(s) to test & debug with your actual physical device and/or ask Dan (the original DTH coder) for assistance ... and donate to him accordingly.