#NEWLINE# def trigger( hass , config , action ) : #NEWLINE# #INDENT# 'Listen for state changes based on configuration.' #NEWLINE# entity_id = config . get ( CONF_ENTITY_ID ) #NEWLINE# below = config . get ( CONF_BELOW ) #NEWLINE# above = config . get ( CONF_ABOVE ) #NEWLINE# value_template = config . get ( CONF_VALUE_TEMPLATE ) #NEWLINE# def state_automation_listener( entity , from_s , to_s ) : #NEWLINE# #INDENT# 'Listen for state changes and calls action.' #NEWLINE# if ( to_s is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# variables = { #NEWLINE# #INDENT# 'trigger' : { #NEWLINE# #INDENT# 'platform' : 'numeric_state' , #NEWLINE# 'entity_id' : entity_id , #NEWLINE# 'below' : below , #NEWLINE# 'above' : above , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# if ( not condition . numeric_state ( hass , to_s , below , above , value_template , variables ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( ( from_s is not None ) and condition . numeric_state ( hass , from_s , below , above , value_template , variables ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# variables [ 'trigger' ] [ 'from_state' ] = from_s #NEWLINE# variables [ 'trigger' ] [ 'to_state' ] = to_s #NEWLINE# action ( variables ) #NEWLINE# #UNINDENT# track_state_change ( hass , entity_id , state_automation_listener ) #NEWLINE# return True