Hi there,
I’ve created a shell command to allow kids to reset the internet access for 1 hour.
I would like to allow the shell command once a day during the week. How can I do that ? I’ve been looking in https://www.home-assistant.io/docs/scripts/conditions/ but an example will be easier.
I’ve found this, this is the beginning ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=9)
- condition: or
conditions:
- condition: time
weekday:
- condition: time
weekday:
- sun
after: ‘08:00:00’
before: ‘10:00:00’
Create separate input_boolean, set it to true when internet access has been used and use different automation to set back to false with time trigger.
Then use this input boolean as condition.
Excellent, thank you but how can I translate that into code?
In your configuration.yaml
input_boolean:
internet_access_request_available:
name: Internet access request available
initial: true
icon: mdi:access-point-network
If input boolean is true the access can be requested. If false then you can run some other actions.
In the automation:
automation:
alias: Request for internet
trigger:
<your trigger>
condition:
condition: state
entity_id: input_boolean.internet_access_request_available
state: 'on'
action:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.internet_access_request_available
- service: ....
Then additionally create the automation e.g. during night to switch input boolean back to on.
1 Like
Thank you for your reply, sorry to ask basic questions but I have only a few days experience in HA.
In fact, I have nothing in automation. Only a few entries in:
configuration.yaml
shell_command:
quota_axel: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] /usr/share/hassio/homeassistant/scripts/expect_quotaaxel.sh
scripts.yaml
quota_axel:
sequence:
- service: shell_command.quota_axel
alias: Quota AXEL
The result is this.
![image](//community-assets.home-assistant.io/original/3X/c/9/c9a8b83ae2c3e93dfe287d87287fe017018924ae.png)
How can I write my automation.yaml ? What is the trigger ?
Yeah no problem!
Few things first.
Please format your code with three tick marks (```) around your code. Or the code formatter button </>. Makes it easier for others ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=9)
Basically everything you have goes into configuration.yaml, one way or another. Unless you make integration from the “integrations” page, use auto discovery etc.
The “automation:” with this rule goes also to configuration.yaml. You can look other configuration examples from the cookbook.
Check also the automation docs.
And back to your case. I’m not giving it handed ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=9)
You can reuse to code from the automation I gave as example. Create the input_boolean first.
Check with the docs how to use condition in a script.
So the script would be roughly:
- Check the condition if access has been used
- (service 1) turn off the input_boolean
- (service 2) call your shell command
Then create the automation to turn on the input boolean again. Use the time trigger.
In the end you would have one input_boolean, two scripts and one automation.
Thank you, I’ll try to find all the necessary information.