Minecraft Server Help

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.

- 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.

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

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.

image

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.

Looking at that you should have got 4 notifications (someone, no one, someone, on one). Not hundreds.

image

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.

can you guide me through this ?

this is greatly appreciated

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 :fire: Moe says make a template or template sensor and trigger off that, give me a sec and I’ll make you one.

1 Like

not a problem, thank you so much for the help - my little one will love this :slight_smile:

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

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.

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)

its the ping, sat watching the sensor and every 30 secs or so when the ping moves i get a message :frowning:

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.

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