I am working on a start/stop system for couple of pumps that are communicating via Home Assistant...
So i have a onhold/onrelease button for turning pump on / off in ui template node:
<div class="pump1">
<md-button> Pump1</md-button>
</div>
<script>
(function($scope) {
$('.pump1').on('touchstart mousedown', function(e) {
e.preventDefault(); //prevent default behavior
$scope.send({"payload" : { "service":'turn_on'} , "topic": 'switch.pump1'});
});
$('.pump1').on('touchend mouseup', function(e) {
e.preventDefault(); //prevent default behavior
$scope.send({"payload" : { "service":'turn_off'} , "topic": 'switch.pump1'});
});
})(scope);
</script>
And i am worried about the following situation:
- I press down the button.
- For some reason the device lost connectivity
- the payload.service ('turn_off') is not sent, and the pump keeps running.
How could i catch any connectivity error, and there for send the second (payload.service ('turn_off')) message?