eTRV Aeotec Radiator Thermostat and Eurotronic Spirit Z-Wave Thermostats

This is my app to drive a boiler switch.

/**
 *  Zone1 Boiler Control
 *
 *  Copyright 2020 Simon Burke
 *
 *  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.
 *
 */
definition(
    name: "Boiler Control Zone1",
    namespace: "SJB",
    author: "Simon Burke",
    description: "Control Zone1 Boiler based on Thermostat Zones",
    category: "Convenience",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
    )

preferences {
    section("Turn on/off this Z-Wave Boiler Switch") {
        input "theswitch", "capability.switch", required: true
	    }
    section("Boiler Boost Switch") {
        input "Booster", "capability.switch", required: true
	    }
    section("Thermostat") {
        input "thermo", "capability.thermostat", title: "SRT321 Thermostats", multiple: true, required: true
        }       
    section("Temperature Sensor") {
        input "temperatureSensor", "capability.temperatureMeasurement", title: "Temperature Sensor", required: false
        }
    section("Temperature Trigger Level") {
        input "temperatureTrigger", "number", title: "Temperature", required:true, multiple:false
        }
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
    unschedule()
	initialize()
}

def initialize() {
	subscribe(thermo, "thermostatMode", thermostatMode)
    runEvery5Minutes('TemperatureHandler')

    thermo?.each {
        if (it.currentValue('battery') < 2)   {
            log.debug  "Zone1 - $it.displayName battery too low - disabled"
        }
            
    	if (it.currentThermostatMode.contains('heat')) and (it.currentValue('battery') > 1) {
    		theswitch.on()  
    		log.debug "Zone1 - Boiler switched on... ${it.displayName} needs heat"
    	}
    }
}

def thermostatMode(evt) {
     if (evt.value.contains('heat')) {
    	theswitch.on()  
    	log.debug "Zone1 - Boiler switched on... ${evt.displayName} called for heat"
    }
}

def TemperatureHandler(evt) {
    def CurrentTemp = temperatureSensor.latestValue("temperature")
    def KnockOnOff = 0
    def BatteryPerCent = 0
    
    if (CurrentTemp>temperatureTrigger-1) {
        log.debug "Zone1 - Temp is $CurrentTemp - at or above $temperatureTrigger"
        KnockOnOff = 0
    } else {  
        log.debug "Zone1 - Temp is $CurrentTemp - too cold - Switching Boiler On"
        KnockOnOff = 1
    } 
        
    thermo?.each {
        BatteryPerCent = it.currentValue('battery')
    	log.debug "Zone1 - $it.displayName current mode is $it.currentThermostatMode  Battery is $BatteryPerCent"    
        
        if (it.currentValue('battery') < 2)   {
            log.debug  "Zone1 - $it.displayName battery too low - disabled"
        }
        
        if (it.currentThermostatMode.contains('heat')) {
            if (it.currentValue('battery') > 1) {
    		    log.debug "Zone1 - $it.displayName needs heat..."
    		    KnockOnOff = 1            
            }
    	}
    }
    
    if ("off" == Booster.currentSwitch ) {
    	log.debug "Zone1 - Booster is Off"
    } else {
       	log.debug "Zone1 - Booster is On"
        KnockOnOff = 1
    }

    if  (KnockOnOff == 1) {
    	theswitch.on()  
        log.debug "Zone1 - Boiler switched on..."
    } else {
        theswitch.off()
        log.debug "Zone1 - Boiler switched off..."
    }
}