how to use virtual switch,switch,media player ?

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!

Moderators: leecollings, remb0

Post Reply
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

how to use virtual switch,switch,media player ?

Post by reza »

hi guys
i want use a misc remote. i have IR codes and i have an espeasy IR transmitter. in domoticz i want use a virtual switch as media player. how to use remote controller in dummy device?
Media_Player.png
Media_Player.png (17.02 KiB) Viewed 446 times
i can not use remote and this is no settings for this.
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by habahabahaba »

You have to write dzVents script actioned by your virtual switch.
So there you write all commands
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: how to use virtual switch,switch,media player ?

Post by waltervl »

And in the Dzvents documentation there is section about how to set the commands https://www.domoticz.com/wiki/DzVents:_ ... dia_Server
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by reza »

can you give me a simple dzvents code for control with virtual switch (media player) for use media player remote control. for example for play/pause or vol+ or vol-
for example i have this code for Vol+(with a espeasy ir trasmitter):
http://192.168.1.199/control?cmd=IRSEND,NEC,FF9867,32
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by habahabahaba »

In my case i have a virtual switch type of Selector for my TV.
But my IR controller needs internet so i need curl installed .

Code: Select all

return {
	on = {
		devices = {87}, -- IDx of your virtual switch
        httpResponses = {
            'TVcontrol_trigger' -- must match with Callback 
                        }
	},
	
        
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'TV control',
	},
	
	execute = function(domoticz, device)
	    
	   local devID = ''
	   local APIkey = ''
	   
	   
	   --local position = device.state
	   local positionName = device.levelName
	   
        local switch = domoticz.devices(87)
        local switchState = switch.level

          -- check current state
          if switchState == 0 then -- on/off 
                      
            devID = '1
            --domoticz.log('Zero', LOG_ERROR)
            
          elseif switchState == 10 then -- chanel +
            
            devID = '2'
            --domoticz.log('10', LOG_ERROR)
            
          elseif switchState == 20 then -- Vol +
            
            devID = '3'
            
            domoticz.log('20 ' .. positionName, LOG_ERROR)
            
          elseif switchState == 30 then -- Vol ++
              
            devID = '4'
            
            --domoticz.log('30 ++', LOG_ERROR)
            
          elseif switchState == 40 then -- Vol -
              
            devID = '5'
            
            --domoticz.log('40 -', LOG_ERROR)
            
          elseif switchState == 50 then -- Vol  -- Vl&#9660
            
            devID = '6'
            domoticz.log('50 --' .. positionName, LOG_ERROR)
            
          elseif switchState == 60 then -- Chanel -
            
            devID = '7'
            --domoticz.log('60 -', LOG_ERROR)
            
          elseif switchState == 70 then
              
            devID = '8'
            --domoticz.log('70', LOG_ERROR)
          end
          
          
          local Command = 'curl -H \"Authorization: Bearer '.. APIkey ..'\" -s -X POST \"https://api.iot.yandex.net/v1.0/scenarios/'.. devID ..'/actions\"'
          
          domoticz.executeShellCommand(Command)
          
          --domoticz.log(switchName, LOG_ERROR)
		
	end
}
In your case if you are in local networ you can use

Code: Select all

domoticz.openURL({
				url = '<YOUR URL>', 
				method = 'POST',
				callback = 'TVcontrol_trigger', -- see httpResponses above.
			}).afterSec(0)
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by reza »

habahabahaba wrote: Saturday 21 September 2024 14:00 In my case i have a virtual switch type of Selector for my TV.
But my IR controller needs internet so i need curl installed .
thank you for help. i am beginner in dzVents. i try but i can not run this . i have an error

Code: Select all

2024-09-21 16:27:00.324 Error: dzVents: Error: (3.1.8) error loading module 'Script #2' from file '/home/pi/Domoticz/scripts/dzVents/generated_scripts/Script #2.lua':
2024-09-21 16:27:00.324 ...pi/Domoticz/scripts/dzVents/generated_scripts/Script #2.lua:30: unfinished string near ''1'
also can not open remote control of virtual device "media player" again.
can you help me more? thank you
please give me one complete dzVents code with that my url and espeasy for my vol+ that i can open remote of virtual device "media player" so i can to complete with other button , thank you
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by habahabahaba »

Try this

Code: Select all

local devId = 87 -- change to your switch IDx

return {
	on = {
		devices = {devId}, -- IDx of your virtual switch
        httpResponses = {
            'MediaPlayer' -- must match with Callback 
                        }
	},
	
        
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'TV control',
	},
	
	execute = function(domoticz, device)
	    
	   local volUp = 'http://192.168.1.199/control?cmd=IRSEND,NEC,FF9867,32'

        local switch = domoticz.devices(devId)
          
          
        domoticz.openURL({
				url = volUp, 
				method = 'POST',
				callback = 'MediaPlayer', -- see httpResponses above.
			}).afterSec(0)
			
        domoticz.log('Volume Up of ' .. switch.name, LOG_INFO)
		
	end
}
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by reza »

habahabahaba wrote: Saturday 21 September 2024 17:11 Try this
thank you. i try and this message write to log every some seconds and repeat.

Code: Select all

2024-09-23 00:26:50.692 Status: EventSystem: Script event triggered: /home/pi/Domoticz/dzVents/runtime/dzVents.lua
2024-09-23 00:26:50.757 Status: dzVents: Info: Handling httpResponse-events for: "MediaPlayer"
2024-09-23 00:26:50.757 Status: dzVents: Info: TV control: ------ Start internal script: Script #1: HTTPResponse: "MediaPlayer"
2024-09-23 00:26:50.775 Status: dzVents: Info: TV control: Volume Up of iii
2024-09-23 00:26:50.775 Status: dzVents: Info: TV control: ------ Finished Script #1
and again remote control on virtual device(media player) can not open and dont show any bottun.
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by habahabahaba »

Sorry, i gave you example for the virtual switch, i dont know such device as virtual device (media player). May be you are using some plugin...

Anyway
one switch = one button
one selector switch = several buttons
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: how to use virtual switch,switch,media player ?

Post by habahabahaba »

2024-09-23_11-41-34.png
2024-09-23_11-41-34.png (4.3 KiB) Viewed 359 times
Thats my virtual Selector Switch. I can put thare up to 10 buttons = up to 10 commands.

Oh, and does your URL "http://192.168.1.199/control?cmd=IRSEND,NEC,FF9867,32" work from browser?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest