I am trying to turn on additional lights when going upstairs to a bonus room and then turn off when coming back downstairs by using my iOS stair counter. I found some similar topics and have attempted the following with no success. The stair counter works correctly and is reflected in HA but I can’t get the increment to trigger an action
I created a binary sensor:
binary_sensor:
- platform: trend
sensors:
floor_ascended:
entity_id: sensor.iphone_floors_ascended
Then I created a automation:
alias: Floor ascended Don
description: ""
trigger:
- platform: state
entity_id: sensor.iphone_floors_ascended
- condition: template
value_template: "{{ trigger.from_state.state | int < trigger.to_state.state | int }}"
action:
- service: notify.mobile_iphone
data:
message: Ascended home floor
- type: turn_on
device_id: 569b7e95b343a4064521cdcd04629e3b
entity_id: switch.lamp_desk
domain: switch
mode: single
You may want to check the traces in the automation to see how far it gets, to make sure your condition works ok (if not, I would change the trigger to be from off to on instead - then no condition needed.
Other thing I noticed, for the last part, I think you need to call a service to turn on the switch…
Thanks. It’s not triggering at all. The light turns on and I get notified when I run it manually, so hopefully it will turn on when it triggers. If not, I can fix that. The trigger is the apparent issue. Unfortunately adding From off To on didn’t cause it to trigger.
Only thing I can think of is that you have your trigger as binary sensor and mine is input_boolean, so off/on may not be valid in your case. You can check the sensor history to see what the states are when it changes, then use those as trigger from-to. Just an idea.
I updated the code to below but still no trigger. Previously, I was attempting to get the trigger signal from the iPhone sensor but here I’m using the binary sensor I created but neither seem to cause a trigger.
alias: Floor Ascend
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.floor_ascended
from: "off"
to: "on"
condition:
- condition: template
value_template: "{{ trigger.from_state.state | int < trigger.to_state.state | int }}"
action:
- service: notify.mobile_iphone
data:
message: Ascended home floor
Your trigger is a binary sensor (on/off) but you are trying to compare numeric values from the trigger in the condition. That’s not going to work. Delete the trend sensor and try this:
alias: Floor Ascend
description: ""
trigger:
- platform: state
entity_id: sensor.iphone_floors_ascended
to: # null to: triggers on all state changes, ignores attribute changes
condition:
- condition: template
value_template: "{{ trigger.from_state.state | int(1) < trigger.to_state.state | int(0) }}"
action:
- service: notify.mobile_iphone
data:
message: Ascended home floor