[SOLVED] Looking for a smart plug that can detect whether the attached item is on

Hey guys,

I appreciate all the help i have already received here. I recently purchased and integrated the Broadlink RM Mini 3 into my OpenHAB system to control a fan and a tv that aren’t smart. I now can turn them off and on, change settings, volume, etc. all from the Basic UI.

This is super nice but i have no way of detecting whether the devices are on or off when i send the commands because the OFF/ON command is the same for both the fan and the tv. I am not that familiar with some of the smart plugs out there but was wondering if there was a smart plug that i could purchase that would tell me whether the attached item (fan or tv in this case) is on or off. To be clear, I would not be switching the item on or off with the smart plug, I would continue to use the RM Mini 3. I just want the smart plug to be on all the time and tell me whether the fan/tv is on and drawing power.

Having this information would allow me to integrate the Broadlink actions into my scenes. For example, i could have a bedtime scene that checks to see whether the TV and fan are on and if they arent, turn them on via the Broadlink.

I hope this was clear. I appreciate any help or suggestions!

Thanks!
JM

Both sonoff and shelly mak e power monitor plugs that can be tied into openhab.

I be lieve the sonoff s31 will monitor power. You have to google but i am 99% confident it could be reflashed also.

2 Likes

I looked into the Sonoff and the Shelly units. The Shelly ones are only for EU and i am NA so those wont work. The S31 was very intriguing and i found a great video from BKHobby on how to load the Tasmota fw on it but I don’t think that the energy monitoring can be integrated into Openhab. If there is a way to do this, im all ears.

If you can load tasmota or esphome and if s31 has energymonitoring then yes through mqtt as far as I know.

1 Like

Thanks. I’ll check into it more. I’m not familiar with MQTT.

Zwave (plus) devices can monitor energy.

I’ve got a similar “problem”, I’ve solved it by using rules and it is supposed to that every IR-devices (TV, Blu-ray, appletv, STB) is controlled by OpenHAB (I use HABMIN as interface). If somehow a device is not in “sync” (ex OH thinks it’s on, but it’s really off because someone push the power button on the device), if made a reset button.

Here is my setup (items and rules):
items

String					IRCommand		"IRCommand"			 {channel="broadlink:rm3:24-df-a7-42-94-79:command"}

Group:Switch:OR(ON,OFF)		IRSwitches        (Home, RestoreOnStartup)
Switch	IR_TV_Power      (IRSwitches)
Switch	IR_SW_Power      (IRSwitches)
String	IR_SW_Hdmi		(IRSwitches)
Switch IR_BR_Power      (IRSwitches)
Switch IR_BR_Netflix    (IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Up		    	(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Down			(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Left			(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Right			(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Enter			(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Return			(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Play			(IRSwitches)						{expire="2s, OFF"}
Switch IR_BR_Pause			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Up		    	(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Down			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Left			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Right			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Enter			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Return			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Play			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Pause			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Power          (IRSwitches)
Switch IR_SB_0			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_1			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_2			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_3			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_4			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_5			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_6			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_7			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_8			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_9			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Channelup			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Channeldown			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Guide			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Recordings			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_PlayPause			(IRSwitches)						{expire="2s, OFF"}
Switch IR_SB_Stop			(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_PlayPause			(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_Up		    	(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_Down			(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_Left			(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_Right			(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_OK			(IRSwitches)						{expire="2s, OFF"}
Switch IR_AT_Menu			(IRSwitches)						{expire="2s, OFF"}


Group:Switch:OR(ON,OFF)	IRScenes		(Home, RestoreOnStartup)
Switch					IR_Netflix      (IRScenes)
Switch                  IR_TV           (IRScenes)
Switch                  IR_AppleTV      (IRScenes)

Switch IR_Reset_Switches	(Home,RestoreOnStartup) 	{expire="2s, OFF"}

rules

val checkFirstS=[SwitchItem item,OnOffType command|
		if (item.state != command) item.sendCommand(command)	
	]

rule "IR switch"
when
    Member of IRSwitches received command
then
    var cmd = triggeringItem.name.replace(triggeringItem.name.split("_").get(0)+"_", "").toUpperCase
	if (cmd.contains("HDMI")){
		cmd=cmd+triggeringItem.state
	}
	logInfo ("cmd",cmd)
    IRCommand.sendCommand(cmd)
end

rule "Start TV Scene"
when
    Member of IRScenes received command
then
    switch (triggeringItem.state) {
        case ON : {
            checkFirstS.apply(IR_TV_Power,ON)
	    	checkFirstS.apply(IR_SW_Power,ON)
            switch (triggeringItem.name) {
                case "IR_Netflix" : {
                    createTimer(now.plusSeconds(6), [|
                        checkFirstS.apply(IR_BR_Power,ON)
                        createTimer(now.plusSeconds(15), [|
                            IR_BR_Netflix.sendCommand(ON)
                        ])
                    ])
                    createTimer(now.plusSeconds(5), [|
                        IR_SW_Hdmi.sendCommand(3)
                    ])
					checkFirstS.apply(IR_SB_Power,OFF)
                }
                case "IR_TV" : {
                    createTimer(now.plusSeconds(6), [|
                        checkFirstS.apply(IR_SB_Power,ON)
                    ])
                    createTimer(now.plusSeconds(5), [|
                        IR_SW_Hdmi.sendCommand(1)
                    ])
                    checkFirstS.apply(IR_BR_Power,OFF)

                }
				case "IR_AppleTV" : {
                    createTimer(now.plusSeconds(5), [|
                        IR_SW_Hdmi.sendCommand(2)
                    ])
                    checkFirstS.apply(IR_BR_Power,OFF)
					checkFirstS.apply(IR_SB_Power,OFF)
				}
            }
			IRScenes.allMembers.filter[name != triggeringItem.name].forEach[postUpdate(OFF)]
        }
		case OFF : {
            switch (triggeringItem.name) {
                case "IR_Netflix" : {
                    checkFirstS.apply(IR_BR_Power,OFF)
                    createTimer(now.plusSeconds(3), [|
    					checkFirstS.apply(IR_SW_Power,OFF)
                    ])
                    createTimer(now.plusSeconds(4), [|
                        checkFirstS.apply(IR_TV_Power,OFF)
                    ])
				}
                case "IR_TV" : {
                    checkFirstS.apply(IR_SB_Power,OFF)
                    createTimer(now.plusSeconds(3), [|
    					checkFirstS.apply(IR_SW_Power,OFF)
                    ])
                    createTimer(now.plusSeconds(4), [|
                        checkFirstS.apply(IR_TV_Power,OFF)
                    ])
	        	}
				case "IR_AppleTV" : {
                    createTimer(now.plusSeconds(3), [|
    					checkFirstS.apply(IR_SW_Power,OFF)
                    ])
                    createTimer(now.plusSeconds(4), [|
                        checkFirstS.apply(IR_TV_Power,OFF)
                    ])
				}
			}
		}
    }
end

rule "Reset IR switches"
when
	Item IR_Reset_Switches received command ON
then
	IRSwitches.allMembers.forEach[postUpdate(OFF)]
	IRScenes.allMembers.forEach[postUpdate(OFF)]
end
1 Like

If you’re willing to use wifi devices, then TP-Link and Belkin make plug-in outlets that monitor energy use. I personally recommend TP-Link, as I’ve found them to be much more reliable.

1 Like

I believe there is a version of the TP-Link smart socket that has an energy monitor built in, that works with the TP-Link binding.

(I only have the HS100 version, so far…)

https://www.tp-link.com/uk/home-networking/smart-plug/hs110/

The really nice feature is that the smart plug can be switched off using the button on it and the state is updated in OH.

As well as…

If it is powered down completely, OH will put the switch state to OFF AND refuse to allow the switch state to be set to ON.

2 Likes

Just picked up a HS110 (US version). Ill let you know how it works! Its a lot cheaper than the Aeotech Smart Plug 6 and the TP-link binding seems to support it.

2 Likes

I just got the TP Link HS110 in the mail last night and was able to get it integrated in OpenHab, my scenes, my rules, etc.

Its working beautifully! I will post my items file, rules file, and sitemap when I get home in case anyone else wants to duplicate what I did.

Now I am going to move onto getting RF codes to work with my RM Pro+

3 Likes

I am a home assistant guy who just lurks here. The Xiaomi smart plug does energy monitoring. It is a zigbee device. Don’t know about openhab and zigbee though.

1 Like

Zigbee works, but would require another dongle.

We have the Xiaomi products working in OH, but I don’t have any myself. I tried ordering some from AliExpress last year and my shipment got returned to the sender without getting past the Chinese border. So, I had to get a refund and didn’t bother trying again.

Okay guys, below are my config files.

Item:

The Fan_Power item activates the Fan_Power_Proxy item that activates the fan (see rules file below).

String   BroadlinkRM31921681189Command   "Command"   {channel="broadlink:rm3:c8-f7-42-40-85-02:command"}
Switch Fan_Power "Fan Power" <fan_box>
String Fan_Power_Proxy "Fan Power" <fan_box> {channel="broadlink:rm3:c8-f7-42-40-85-02:command"}

Transform: broadlink.map
Fan_On=26007a002.......................

Rules:

The fan only has one power command. That command will change the state of the fan whether its on or off. This is a problem as @ljsquare mentioned above. I am using the current draw of the fan to detect the actual state of the fan. The first rule reads like this (in plain english):
If Fan_On (item) is changed to ON and the fan drawing less than 0.30A (indicating the fan is, in fact off) then send the power command. The opposite of the above statement is also true.

rule "Fan on"
when
    Item Fan_Power changed
then
    var watt = MasterBRFanSmartplugCurrent.state as Number
    if(Fan_Power.state == ON && watt <= 0.30) { Fan_Power_Proxy.sendCommand("Fan_On")}
    if(Fan_Power.state == OFF && watt >= 0.30) { Fan_Power_Proxy.sendCommand("Fan_On")}
end

The second rule is there to check the actual state of the fan and update the Fan_On item accordingly. If i trigger the fan manually and this rule wasn’t there, the Fan_On would never update. This rule reads very similarly to the previous rule in form.

rule "Fan on Check"
when
    Item Fan_Power_Proxy received update or
    Time cron "0 0/1 * * * ?" //every minute
then
    createTimer(now.plusSeconds(16), [
    var watt = MasterBRFanSmartplugCurrent.state as Number
    if(Fan_Power.state == ON && watt <= 0.30) { Fan_Power.sendCommand(OFF)}
    if(Fan_Power.state == OFF && watt >= 0.30) { Fan_Power.sendCommand(ON)}
    ])
end

This last rule is just in case the TP-Link HS110 smart plug gets turned off. I am not using the HS110 to control the fan, i am just using it to detect the current draw of the fan so I always want this smart plug to be on. This rule makes sure its always on.

rule "Fan Smart Outlet Always On"
when
    System started or
    Item MasterBRFanSmartplugSwitch changed
then
    createTimer(now.plusSeconds(1), [
    MasterBRFanSmartplugSwitch.sendCommand(ON)
    ])
end

Sitemap:
Switch item=Fan_Power

I hope this helps someone else who was in my situation. With these 2 devices (the HS110 and the Broadlink RM Mini 3) I am able to make any ‘dumb’ device that can be controlled via IR or RF to be smart and integrated into Openhab.

1 Like