hardys
(steven hardy)
September 6, 2019, 2:13pm
1
Hi,
I am trying to set an automation off based on activity (i.e. a user connected to my home minecraft server) I have the sensor in Home Assistant working perfectly but I dont know what sort of automation i need (number, state etc …)
These are the results from the sensor;
Please help as my Son will be so happy if I get alerted when he is online or I flash lights when i go online when working away.
tom_l
September 6, 2019, 2:23pm
2
- id: minecraft_server_user
alias: 'Minecraft Server User'
trigger:
platform: state
entity_id: sensor.finley_dads_minecraft_server
action:
- service: persistent_notification.create
data_template:
title: "Yo, Admin"
message: "There are {{ states('sensor.finley_dads_minecraft_server') }} users connected to Dad's Minecraft server"
- other services here (flash light's etc...)
Note, this will trigger upon connection and disconnection of users.
hardys
(steven hardy)
September 6, 2019, 2:56pm
3
This just gave me hundreds of notifications when no one was connected ?
Ideally I want a message when it becomes greater that 0 and thats it
- id: '1567778733250'
alias: Minecraft Server Activity
trigger:
- entity_id: automation.minecraft_server_activity
platform: state
condition: []
action:
- data:
message: There are {{ states('sensor.finley_dads_minecraft_server') }} users
connected to our Minecraft Server
service: persistent_notification.create
tom_l
September 6, 2019, 3:04pm
4
Oh. That’s not good. It should only notify you when the state changes. Maybe it goes “unavailable” a lot?
What does the history of the sensor look like?
Add an entities card to Lovelace with the sensor.finley_dads_minecraft_server
entity and click on it to see the more info history pop-up.
Greater than zero is going to be tricky (but not unpossible) due to the n/n state rather than just a number.
tom_l
September 6, 2019, 3:08pm
6
Click on the title of the pop-up again so it expands to fill the screen so we can see how many cyan state changes are in that one bit. It does look like more than one.
tom_l
September 6, 2019, 3:10pm
8
Looking at that you should have got 4 notifications (someone, no one, someone, on one). Not hundreds.
I would template the “Users online:” attribute instead of the state. Something is triggering the state to change, likely to do with the component/integration.
hardys
(steven hardy)
September 6, 2019, 3:15pm
12
can you guide me through this ?
this is greatly appreciated
tom_l
September 6, 2019, 3:17pm
13
Hmm. Maybe it’s triggering when the attributes change as well (ping could be the culprit). Sorry about having to delete all those notifications. A restart will clear them more easily than pressing “X” 635 times.
As Moe says make a template or template sensor and trigger off that, give me a sec and I’ll make you one.
1 Like
hardys
(steven hardy)
September 6, 2019, 3:18pm
14
not a problem, thank you so much for the help - my little one will love this
hardys
(steven hardy)
September 6, 2019, 3:19pm
15
this is what i have at the moment;
- id: '1567778733250'
alias: Minecraft Server Activity
trigger:
- entity_id: automation.minecraft_server_activity
platform: state
condition: []
action:
- data:
message: There are {{ states('sensor.finley_dads_minecraft_server') }} users
connected to our Minecraft Server
service: notify.ios_steves_iphone
1 Like
tom_l
September 6, 2019, 3:23pm
16
Ha! I see the problem. That ain’t what I wrote. Look closely at the entity_id in the trigger.
- id: minecraft_server_user
alias: 'Minecraft Server User'
trigger:
platform: state
entity_id: sensor.finley_dads_minecraft_server
action:
- service: persistent_notification.create
data_template:
title: "Yo, Admin"
message: "There are {{ states('sensor.finley_dads_minecraft_server') }} users connected to Dad's Minecraft server"
- other services here (flash light's etc...)
The entity id in the trigger should be the sensor. not an automation.
hardys
(steven hardy)
September 6, 2019, 3:27pm
17
I just spotted that too, just testing now hold the line - just got one message for 0/2 … logging on … another message 1/2 users … it still seems to send a message duplicating itself (not as many but still doing it)
hardys
(steven hardy)
September 6, 2019, 3:29pm
18
its the ping, sat watching the sensor and every 30 secs or so when the ping moves i get a message
tom_l
September 6, 2019, 3:30pm
19
Cool.
Ok. Let’s bust out the number of users with a template sensor and use that. Give me a sec.
Hmmm, why is the Users Online:
attribute empty? That’s not helping.
Make this Sensor:
sensor:
- platform: template
sensors:
minecraft_server_users:
friendly_name: Minecraft Server Users
entity_id: sensor.finley_dads_minecraft_server
value_template: "{{ states('sensor.finley_dads_minecraft_server')|replace('/2', '') }}"
And change your automation to:
Never mind. Sorted. As below.
hardys
(steven hardy)
September 6, 2019, 3:34pm
20
here is the semi working code:
- id: '1567778733250'
alias: Minecraft Server Activity
trigger:
- entity_id: sensor.finley_dads_minecraft_server
platform: state
condition: []
action:
- data:
message: There are {{ states('sensor.finley_dads_minecraft_server') }} users
connected to our Minecraft Server
service: notify.ios_steves_iphone