jchh
((not John))
February 3, 2024, 12:54pm
1
HI all,
I know I can continue_on_error
but can I make an if/then out of an error?
Background : I have a script that turns on a camera, moves it to a position and then sends an I'm on
message. The move to position is performed by a select.select_option
and its state is always unknown
as the camera does not feedback its last position. Sometimes on turning thr camera on, select.select_option
fails and I want to delay a couple of seconds and try it again.
I know I could simply put a delay in at the start - turn on camera, delay, move to position, but it started me thinking about taking an action if the previous sequence failed.
jchh
((not John))
February 3, 2024, 4:03pm
3
Hi - thanks for replying.
I have the scripts/switch/automations in a single package…
Package
script: #-----------------------------------------------------------------------
tapo_notify_status:
alias: "Tapo: Notify camera status"
mode: restart
icon: mdi:message-text-outline
sequence:
- choose:
- conditions:
- condition: state
entity_id: switch.tapo_c220_privacy
state: "on"
sequence:
- service: notify.pushover
data:
title: "Petit Pois"
message: "Camera is off"
data:
subtitle: "Camera"
sound: tugboat
- conditions:
- condition: state
entity_id: switch.tapo_c220_privacy
state: "off"
sequence:
- service: notify.pushover
data:
title: "Petit Pois"
message: "Camera is on"
data:
subtitle: "Camera"
sound: tugboat
- conditions:
- condition: state
entity_id: switch.tapo_c220_privacy
state: "unavailable"
sequence:
- service: notify.pushover
data:
title: "Petit Pois"
message: "Camera is unavailable"
data:
subtitle: "Camera"
sound: tugboat
tapo_move_to_door:
alias: "Tapo: Point camera at door"
mode: restart
sequence:
- service: select.select_option
target:
entity_id: select.tapo_c220_move_to_preset
data:
option: door
tapo_move_to_wall:
alias: "Tapo: Point camera at wall"
mode: restart
sequence:
- service: select.select_option
target:
entity_id: select.tapo_c220_move_to_preset
data:
option: wall
switch: #———————————————————————————————————————————————————————————————————————
- platform: template
switches:
tapo_camera:
friendly_name: "Tapo: control"
value_template: "{{ is_state('switch.tapo_c220_privacy', 'off') }}"
# camera on ------------------------------------------
turn_on:
# privacy off
- service: switch.turn_off
target:
entity_id: switch.tapo_c220_privacy
# allow for wake-up if off for a while
- delay: 00:00:05
# move to door
- service: select.select_option
continue_on_error: true
target:
entity_id: select.tapo_c220_move_to_preset
data:
option: door
# tamper protection on
- service: select.select_option
continue_on_error: true
target:
entity_id: select.tapo_c220_tamper_detection
data:
option: normal
# notify status
- service: script.turn_on
target:
entity_id: script.tapo_notify_status
# camera off -----------------------------------------
turn_off:
# tamper protection off
- service: select.select_option
target:
entity_id: select.tapo_c220_tamper_detection
data:
option: "off"
# move to wall
- service: select.select_option
target:
entity_id: select.tapo_c220_move_to_preset
data:
option: wall
# allow move to complete
- delay: 00:00:07
# privacy off
- service: switch.turn_on
target:
entity_id: switch.tapo_c220_privacy
# notify status
- service: script.turn_on
target:
entity_id: script.tapo_notify_status
icon_template: >-
{% if is_state('switch.tapo_c220_privacy', 'off') %} mdi:cctv
{% else %} mdi:cctv-off
{% endif %}
automation: #-------------------------------------------------------------------
- alias: "Tapo: Auto on:off"
id: tapo_on_off
mode: single
trigger:
# someone enters/leaves
- platform: state
entity_id: zone.home
# HA startup
- platform: homeassistant
event: start
action:
- if:
# no-one home
- "{{ states('zone.home') == '0' }}"
# switch is off
- condition: state
entity_id: switch.tapo_camera
state: "off"
then:
- service: switch.turn_on
target:
entity_id: switch.tapo_camera
- if:
# someone home
- "{{ states('zone.home') != '0' }}"
# switch is on
- condition: state
entity_id: switch.tapo_camera
state: "on"
then:
- service: switch.turn_off
target:
entity_id: switch.tapo_camera
- alias: "Tapo: notify on:off"
id: tapo_notify
mode: restart
trigger:
- platform: state
entity_id: switch.tapo_camera_privacy
action:
- service: script.turn_on
target:
entity_id: script.tapo_notify_status
I am currently using a 5 sec delay to hopefully overcome the problem.