I see. So now I set my “current_state = new” all the rest is the same. It still fires when the state has not change. I wonder… Even if the state does not change but an attribute does, that will fire the listener?
Comparing the new to the old for a real change seems to work.
Current version:
import appdaemon.plugins.hass.hassapi as hass
import json
import urllib
class left_arived_home(hass.Hass):
def initialize(self):
self.device_tracker = 'device_tracker.' + self.args['devicetracker_home_status']
self.device_tracker_full_name = self.get_state(self.device_tracker, attribute='full_name')
self.listen_state(self.left_arived_home_callback,
self.device_tracker,
new='home')
self.listen_state(self.left_arived_home_callback,
self.device_tracker,
new='not_home')
self.log("Automaintion initialize.")
def left_arived_home_callback(self, entity, attribute, old, new, kwargs):
self.log('callback started')
message = ""
#current_state = self.get_state(self.device_tracker)
current_state = new
self.log("Current State '"
+ self.device_tracker_full_name
+ " is "
+ current_state
+ " old state: "
+ old
+ " new state: "
+ new
+ "'")
send_message = (old != new)
if current_state == 'not_home':
message = self.device_tracker_full_name + " has left "
if current_state == 'home':
message = self.device_tracker_full_name + " has arived "
if send_message:
self.call_service("notify/"+self.args['send_alert_to'],title="",message=message)
self.log("\n****************************\n"
+ message + "\n"
+ "****************************\n"
+ "Message Sent")