Set Switchbot State based on Ping Sensor

Hello,

Would appreciate advice in which direction to go in…

I have recently purchased a Switchbot bot for a NAS which does not have Wake on LAN capabilities.

It works as expected but I am hoping to make it more state aware than just being a dumb device.
I have setup a PING sensor for my NAS and now would like to use it to report the current state of my Switchbot bot.

Is such a thing possible? Can you force an entities ‘state’ using a ping sensor?

My sensor configuration is:

binary_sensor:
  - platform: ping
    name: nas
    host: 192.168.111.101
    scan_interval: 30

My customize.yaml is:

switch.nas:
  assumed_state: false
  icon: mdi:nas

If it is not possible to set the state of an entity/switch, can I use an automation or script which uses conditions to either turn on or off?

For example; I have tried this automation:

id: '1647631432696'
alias: Turn on NAS
description: ''
trigger: []
condition:
  - condition: state
    entity_id: binary_sensor.nas
    state: 'off'
action:
  - type: toggle
    device_id: 7f961fc842737da900c446e0725c2655
    entity_id: switch.nas
    domain: switch
mode: single

But it does not work (it activates the switchbot regardless). I want it to toggle the switchbot if the NAS is off (ping failed) and I’ll create a second automation to turn it off if the NAS is on. I tried a script but couldn’t get that working either.

I need it to work this way as the Switchbot activates regardless of ‘Alexa, turn off/on NAS’. I do not always know the state of my NAS and so sometimes it powers down when I say ‘Alexa, turn on NAS’.

I’ll setup routines within Alexa to ensure the right automation is fired upon either phrase.

Any assistance would be much appreciated.

Many thanks.

OK - I have managed to setup two scripts as follows:

nas_on:
  alias: NAS ON
  sequence:
  - condition: state
    entity_id: binary_sensor.nas
    state: 'off'
  - type: toggle
    device_id: 7f961fc842737da900c446e0725c2655
    entity_id: switch.nas
    domain: switch
  mode: single
  icon: mdi:power-plug
nas_off:
  alias: NAS OFF
  sequence:
  - condition: state
    entity_id: binary_sensor.nas
    state: 'on'
  - type: toggle
    device_id: 7f961fc842737da900c446e0725c2655
    entity_id: switch.nas
    domain: switch
  mode: single
  icon: mdi:power-plug-off-outline

Is this the best method? Is there any way to integrate this into one toggle switch which I can then add to lovelace? And can it update the status of the switchbot switch?

Thanks

I’m looking to do something similar - did you ever find a more elegant solution?