You can alter the visibility of a group with an automation:
https://home-assistant.io/docs/configuration/group_visibility/
You can probably use a template sensor to determine whether the entity exists/is down or not.
You can alter the visibility of a group with an automation:
https://home-assistant.io/docs/configuration/group_visibility/
You can probably use a template sensor to determine whether the entity exists/is down or not.
I have already tried but the results are same. My config is below
sensor.yaml file
platform: template
sensors:
c200:
value_template: “{{ ‘Online’ if is_state(‘device_tracker.c200’, ‘home’) else ‘Offline’ }}”
automation.yaml:
trigger:
platform: state
entity_id: sensor.c200
state: ‘not_home’
action:
service: group.set_visibility
entity_id: group.c200
data:
visible: False
groups.yaml
network_devices:
entities:
group.c200
c200:
entities:
sensor.c200
It’s hard to read unformatted YAML. Use preformatted text
But it looks like you’re looking for “not_home” as a state for sensor.c200, yet your value_template will return “Online” or “Offline”. So the state will never be “not_home”.
Also - I’m assuming that your value_template has no errors. Have you checked it in the template dev tool?
Yes, that was just a example, the template was giving home and not_home and the homeassistant is running without any configuration errors.
automation.yaml
- alias: Show Poweroff Control
hide_entity: False
trigger:
platform: state
entity_id: switch.mycloud_plug
state: 'on'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: True
- alias: Hide Poweroff Control
hide_entity: False
trigger:
platform: state
entity_id: switch.mycloud_plug
state: 'off'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: False
groups.yaml
controltab:
name: Control
view: yes
entities:
- group.device_admin
- group.app_admin
- group.switches
device_admin:
name: Device Admin
entities:
- input_boolean.restart_tplink
- input_boolean.restart_rpi
- group.mycloud_control
mycloud_control:
name: MyCloud Control
entities:
- input_boolean.poweroff_mycloud
input_boolean.yaml
poweroff_mycloud:
initial: off
switch.yaml
- platform: kankun
switches:
mycloud_plug:
name: mycloud_plug
host: 192.168.x.x
If you directly activate the automation, does it work? How about if you change the visibility via the services dev tool?
The service JSON will look like:
{"entity_id":"group.mycloud_control","visible":"false"}
Yes, after calling via dev tool, the control is hiding. Why it was not hiding through config?
That suggests there’s a problem with your trigger. Keep in mind that state triggers are only triggered when the state changes. So turn mycloud_plug off and back on to see if that automation works.
Are you seeing any errors in home-assistant.log about YAML formatting?
you could try replacing
state: 'on'
with
from: 'off'
to: 'on'
Tried and still the same.
Is that because the mycloud_plug state is off when initialize and never switched on to activate the trigger part in automation?.
The trigger part in automation triggers only when there is an change in the state or will that consider initial state also?. For example, if a template_sensor found a device is offline, then it initiates with ‘off’ as state, will the automation trigger?
I’m pretty sure it’ll only trigger on state change. But I may be wrong there. @ReneTode do you know the answer to that?
i can only give back what i know from what i read in the docs and on the forums
i have no automations at all (all trough appdaemon)
i know that state changes are registered when HA is started.
for instance: i have some 433 mhz switches and they Always get triggered when HA starts. (quite annoying actually)
initial state for most devices is “unknown” or “none”
the it changes to the actual state.
i know thats part of the reason they implemented the “from:” at one time.
if something triggers at startup? i would say, try it.
I tried to change the state of sensor on the front-end and the automation triggered and hides/shows the control. So, basically when the hass initiates, the automation is not triggered.
I have added additional automation rules with platform as homeassistant, now working as expected.
Added 4 rules to show/hide the control upon start.
- alias: Show MyCloud Poweroff Control
hide_entity: False
trigger:
platform: state
entity_id: sensor.mycloud
state: 'Online'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: True
- alias: Hide MyCloud Poweroff Control
hide_entity: False
trigger:
platform: state
entity_id: sensor.mycloud
to: 'Offline'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: False
- alias: Show MyCloud Poweroff Control 2
hide_entity: False
trigger:
platform: homeassistant
event: start
condition:
condition: state
entity_id: switch.mycloud_plug
state: 'on'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: True
- alias: Hide MyCloud Poweroff Control 2
hide_entity: False
trigger:
platform: homeassistant
event: start
condition:
condition: state
entity_id: switch.mycloud_plug
state: 'off'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: False
A tip that some miss - you can probably combine these. An automation can have multiple triggers, then use conditions to filter out only the situation you want.
Something like
- alias: Show MyCloud Poweroff Control
hide_entity: False
trigger:
- platform: state
entity_id: sensor.mycloud
state: 'Online'
- platform: homeassistant
event: start
condition:
condition: state
entity_id: switch.mycloud_plug
state: 'on'
action:
- service: group.set_visibility
entity_id: group.mycloud_control
data:
visible: True
If I comibine, not working. because homeassistant -> event start doesn’t work with switch.mycloud_plug, the state may not be initiated when started the homeassistant.
False is with capital letter if it matters?