Tom-Hirschberger/MMM-Screen-Powersave-Notification

Turning Screen on/off with MQTT

Closed this issue · 5 comments

Hi,

i'm having trouble to turn on and off the screen.

I've installed MQTTbridge and it's connected to the broker.
Then i've tested if xrandr is working and found that the default is set to WAYLAND not X11, so i turned back to X11 to get xrandr working "sudo raspi-config" - select "6 - advanced options" then "A6-Wayland" and switch to X11 (should be niticed in readme ;) found here

But i can't figure out how to toggle the xrandr_control script

When sending a payload OFF to the Topic MMM-Screen-Powersave-Notification is responding with SCREENSAVE_ENABLED but screen stays on. When sending ON, nothing happens ( i guess because Screen is already on)

config.js

{
	module: 'MMM-Screen-Powersave-Notification',
	config:
	{
		delay: 60,
		profiles:
		{
			screenStatusCommand: "./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control status HDMI-1",
			screenOnCommand: "./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control on HDMI-1", 
			screenOffCommand: "./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control off HDMI-1"
		}
	}
},

mqttDictionary.js

var mqttHook = [
    {
      mqttTopic: "magicmirror/state/monitor",
      mqttPayload: [
        {
          payloadValue: "ON",
          mqttNotiCmd: ["Command 1"]
        },
      ],
    },
    {
      mqttTopic: "magicmirror/state/monitor",
      mqttPayload: [
        {
          payloadValue: "OFF",
          mqttNotiCmd: ["Command 2"]
        },
      ],
    },
  ];
var mqttNotiCommands = [
    {
      commandId: "Command 1",
      notiID: "SCREEN_ON",
      notiPayload: {action: 'screenOnCommand'}
    },
    {
      commandId: "Command 2",
      notiID: "SCREEN_OFF",
      notiPayload: {action: 'screenOffCommand'}
    },
  ];

  module.exports = { mqttHook,  mqttNotiCommands};

Hi,

i am very busy with my twins at the moment but i will try to add the hint of how to switch back to X11 from Wayland in Bookworm to the readme.

I am still using Debian Bullseye with my mirror at the moment and do not have time to prepare a test environment at the moment.

Does the xrandr_control work if you call it in the shell? You can try to call the script with the options in the config and check if the screen goes on and off. But you need to call it via ssh shell and not directly in the GUI as you will shout-off the screen if it works and will not be able to shout it on again.

Your MQTT config looks good except the action in the notiPayload. The module only supports a force option but will ignore the action.

Okay, i've changed notiPayload: {action: 'screenOffCommand'} to notiPayload: {force: true}

trying to call the script ./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control off HDMI-1
gives
display_power=0
and Display turns off, so it's working. With on it's comming back and
display_power=1

When sending OFF to topic magicmirror/state/monitor still only getting SCREENSAVE_ENABLED notification from MMM-Screen-Powersave-Notification adn screen son't turn off.

Also also line 20 should be changed from HDMI-1 to $port to respect the call with specitic port given.

Hi,

just quick fixed the port in line 20. Thank you for the hint.

Double checked your module config. You don't need the profile:.
The config is still valid JSON so it will be accepted but the custom commands will not be set.

It should work if you change your module config to:

{
	module: 'MMM-Screen-Powersave-Notification',
	config:
	{
		delay: 60,
		screenStatusCommand: "./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control status HDMI-1",
                screenOnCommand: "./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control on HDMI-1", 
	        screenOffCommand: "./modules/MMM-Screen-Powersave-Notification/controlScripts/xrandr_control off HDMI-1"
	}
},

Thanks, it's workin now.... dind't see i still had it in profile{}

Great to hear this