Sync interface ON\OFF with POE

Hello guys!
Maybe someone can help with advice or script.
On the POE router, I need following: when the interface is turned off, POE is also turned off and vice versa.
Thanks!

When the script disable/enable the interface, add a line for off/auto the poe…

Yep, this would be something like:
/interface ethernet disable
or
/interface ethernet disable [find =]
and
/interface ethernet poe set poe-out=off

but it is not clear how the OP intends to disable the interface (by script or manually) maybe what is asked for is a script running that every x seconds/minutes checks whether the interface is enabled or disabled and accordingly switches poe on or off.

@vercetti
Please explain/detail what you want to do.

Why not? :confused:

Just tested (example):

/interface ethernet disable [find mac-address=0C:10:7B:A0:00:01]

/interface ethernet enable [find mac-address=0C:10:7B:A0:00:01]

and they seem to work just fine.

1 + 1 = 2
but also
1 + 88 - 99 + 12 = 2

The point is that do not have any sense if interface name (or default interface name) can be used directly…

[italian]
è come il pesce ratto, può piacere o non piacere, non discuto …
[/italian]
:laughing:

The logic is as follows, only there is one nuance, I can’t get the current statuses of the interfaces lol
partially generated by chatgpt.....

  :local interfaces ("ether1", "ether2", "ether3", "ether4", "ether5")
  
  :foreach interfaceName in=$interfaces do={
    :local poeInterface [/interface find name=$interfaceName]
    
    :if ($poeInterface != "") do={
      :local linkState [/interface get $interfaceName link]
      
      :if ($linkState = "down") do={
        :local poeEnabled [/interface get $poeInterface poe-out]
        
        :if ($poeEnabled = "auto-on") do={
          /interface poe set $poeInterface poe-out=off
          :log info ("POE on interface $interfaceName has been disabled.")
        }
      } else={
        :local linkState [/interface get $interfaceName link]
        :if ($linkState = "up") do={
          :local poeDisabled [/interface get $poeInterface poe-out]
          
          :if ($poeDisabled = "off") do={
            /interface poe set $poeInterface poe-out=auto-on
            :log info ("POE on interface $interfaceName has been enabled.")          
          
        }
      }
    }

Maybe try on command line:
/interface ethernet poe monitor [find]

https://wiki.mikrotik.com/wiki/Manual:PoE-Out#RouterOS_2

Maybe you’re going about this the wrong way. Not enough information provided

If all your end devices are power from the router/switch. Why not just turn off Poe. That will then in turn make the interface “not running”, and you can easily see/script based upon that if you have other things that depend on the interface status

Why would you go through all this effort?

I use Mikrotik integration in Home Assistant, which expose ports, trafic sensors and many many another.
So i have POE router with cameras connected to it.
I have automation, which, in the event of a battery discharge (from which the entire infrastructure is powered), smoothly disconnects the consumers specified in the automation.
So, the switch, which can be controlled from the home assistant, turns off only ethernet, while the POE on the interface remains turned on and consumes electricity.
It’s actually for these purposes that I want to write a script to bind these events.
I hope I explained.

But i guess thats my point really.

Home Assistant is using ssh or api to disable a port by running something like

/interface ethernet set disabled=yes ether24 for example can’t you just change that to disable the poe instead? i.e. interface ethernet poe set poe-out=off ethet24