NS Panel Sonoff With Tasmota and MQTT

Moderator: leecollings

Post Reply
codercrack
Posts: 3
Joined: Thursday 11 March 2021 18:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

NS Panel Sonoff With Tasmota and MQTT

Post by codercrack »

Hi !!
I embarked on the NSPanel adventure.
I use the "Autodiscovery of Tasmota Devices" plugin, which works wonderfully and it shows me the two switches as well as the temperature of the NSPanel (Internal).
Only, I don't know how to process the thermostat information received from the NSPanel in MQTT with the topic : tele/nspanel_7BE460/RESULT.
Handler::onMQTTPublish: device: nspanel_7BE460, cmnd: cmnd/nspanel_7BE460, tail: RESULT, message: {'NSPanel': {'ATCMode': 0, 'ATCExpect0': 24}}

Code: Select all

022-06-24 06:29:48.073 MQTT Discovery: Received 57 bytes of data
2022-06-24 06:29:48.074 MQTT Discovery: 30 37 00 1a 74 65 6c 65 2f 6e 73 70 61 6e 65 6c 5f 37 42 45 07..tele/nspanel_7BE
2022-06-24 06:29:48.074 MQTT Discovery: 34 36 30 2f 52 45 53 55 4c 54 7b 22 4e 53 50 61 6e 65 6c 22 460/RESULT{"NSPanel"
2022-06-24 06:29:48.074 MQTT Discovery: 3a 7b 22 41 54 43 45 6e 61 62 6c 65 22 3a 31 7d 7d .. .. .. :{"ATCEnable":1}}
2022-06-24 06:29:48.075 MQTT Discovery: onMQTTPublish: tele/nspanel_7BE460/RESULT:b'{"NSPanel":{"ATCEnable":1}}'
2022-06-24 06:29:48.091 MQTT Tasmota: Received 57 bytes of data
2022-06-24 06:29:48.091 MQTT Tasmota: 30 37 00 1a 74 65 6c 65 2f 6e 73 70 61 6e 65 6c 5f 37 42 45 07..tele/nspanel_7BE
2022-06-24 06:29:48.091 MQTT Tasmota: 34 36 30 2f 52 45 53 55 4c 54 7b 22 4e 53 50 61 6e 65 6c 22 460/RESULT{"NSPanel"
2022-06-24 06:29:48.091 MQTT Tasmota: 3a 7b 22 41 54 43 45 6e 61 62 6c 65 22 3a 31 7d 7d .. .. .. :{"ATCEnable":1}}
2022-06-24 06:29:48.092 MQTT Tasmota: Handler::onMQTTPublish: topic: tele/nspanel_7BE460/RESULT
2022-06-24 06:29:48.092 MQTT Tasmota: Handler::onMQTTPublish: device: nspanel_7BE460, cmnd: cmnd/nspanel_7BE460, tail: RESULT, message: {'NSPanel': {'ATCEnable': 1}}
2022-06-24 06:29:48.092 MQTT Tasmota: tasmota::findDevices: fullName: nspanel_7BE460, Idxs [1, 2, 3]
2022-06-24 06:29:48.175 MQTT Discovery: Received 71 bytes of data
2022-06-24 06:29:48.175 MQTT Discovery: 30 45 00 1a 74 65 6c 65 2f 6e 73 70 61 6e 65 6c 5f 37 42 45 0E..tele/nspanel_7BE
2022-06-24 06:29:48.175 MQTT Discovery: 34 36 30 2f 52 45 53 55 4c 54 7b 22 4e 53 50 61 6e 65 6c 22 460/RESULT{"NSPanel"
2022-06-24 06:29:48.175 MQTT Discovery: 3a 7b 22 41 54 43 4d 6f 64 65 22 3a 30 2c 22 41 54 43 45 78 :{"ATCMode":0,"ATCEx
2022-06-24 06:29:48.175 MQTT Discovery: 70 65 63 74 30 22 3a 32 34 7d 7d .. .. .. .. .. .. .. .. .. pect0":24}}
2022-06-24 06:29:48.176 MQTT Discovery: onMQTTPublish: tele/nspanel_7BE460/RESULT:b'{"NSPanel":{"ATCMode":0,"ATCExpect0":24}}'
2022-06-24 06:29:48.193 MQTT Tasmota: Received 71 bytes of data
2022-06-24 06:29:48.193 MQTT Tasmota: 30 45 00 1a 74 65 6c 65 2f 6e 73 70 61 6e 65 6c 5f 37 42 45 0E..tele/nspanel_7BE
2022-06-24 06:29:48.193 MQTT Tasmota: 34 36 30 2f 52 45 53 55 4c 54 7b 22 4e 53 50 61 6e 65 6c 22 460/RESULT{"NSPanel"
2022-06-24 06:29:48.193 MQTT Tasmota: 3a 7b 22 41 54 43 4d 6f 64 65 22 3a 30 2c 22 41 54 43 45 78 :{"ATCMode":0,"ATCEx
2022-06-24 06:29:48.196 MQTT Tasmota: 70 65 63 74 30 22 3a 32 34 7d 7d .. .. .. .. .. .. .. .. .. pect0":24}}
2022-06-24 06:29:48.197 MQTT Tasmota: Handler::onMQTTPublish: topic: tele/nspanel_7BE460/RESULT
2022-06-24 06:29:48.197 MQTT Tasmota: Handler::onMQTTPublish: device: nspanel_7BE460, cmnd: cmnd/nspanel_7BE460, tail: RESULT, message: {'NSPanel': {'ATCMode': 0, 'ATCExpect0': 24}}
2022-06-24 06:29:48.197 MQTT Tasmota: tasmota::findDevices: fullName: nspanel_7BE460, Idxs [1, 2, 3] 
codercrack
Posts: 3
Joined: Thursday 11 March 2021 18:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NS Panel Sonoff With Tasmota and MQTT

Post by codercrack »

Hello,
I think I found the solution with Node Red
Capture d’écran du 2022-06-26 18-37-35.png
Capture d’écran du 2022-06-26 18-37-35.png (35.14 KiB) Viewed 4082 times
Setting and powering up the Thermostat: OK
Management of the first switch: OK
For the others (Index 2 to Index 8) it's more complicated, because even "live" on the Sonoff they don't hold their states.

It's progressing slowly, but it's progressing!!! :lol:
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: NS Panel Sonoff With Tasmota and MQTT

Post by Derik »

He Hoi...

Did you have teh panel working better?
Is there more info?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: NS Panel Sonoff With Tasmota and MQTT

Post by Quax1507 »

I would be also interested ;-)
Gingerpale
Posts: 10
Joined: Wednesday 13 January 2016 16:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: NS Panel Sonoff With Tasmota and MQTT

Post by Gingerpale »

I'm trying to control the widgets (on NSPanel page 2) and as a first step I'm setting the following rule:

Rule1 on NSPanel#params#switch do Publish domoticz/in {"command": "switchlight", "idx": 100, "switchcmd": "%value%"} endon
Rule1 1

So by pressing any widget (unfortunately not a widget with a specific idx yet :? ) on NSPanel this could turn on or off domoticz device with idx 100 in this example.

But it doesn't work since the NSPanel#params#switch returns %value% as "ON" or "OFF" in capitals and it seems only "On" or "Off" are valid to use with "switchcmd".
Where and why is it generated in capitals? I tried to search for a solution but couldn't find it.
Rpi4B,RFX433e,PiFace2, LCD, Hue bridge, Alexa (+TTS), HA-Bridge, Sonoff NSPanel, Sonoff RF (+IR) bridge, Nefit CV, Tasmota/MQTT, Enphase Solar, Smartmeter, Alarm I/F, H13726B Weather Station, CM180 Energy meter, Sonoff, KaKu, Tuya, Gledopto, AriLux,...
Gingerpale
Posts: 10
Joined: Wednesday 13 January 2016 16:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: NS Panel Sonoff With Tasmota and MQTT

Post by Gingerpale »

I have integrated the NSPanel (with Tasmota) into Domoticz and I finally got it working.
Most trouble I experienced with the mirroring of the states of the NSPanel widgets: how to trigger on a specific widget ID and retrieve its action On/Off at the same time? Funny thing is that the widgets return their state in capitals (ON/OFF) and this doesn’t work!
Finally I came up with a rule running in the NSPanel that did the trick for a noob like me.
There might/must be many other and easier ways to achieve all this but below is how I managed and I hope it is of use to someone…
I’m always open for good suggestions or additions, e.g. how to optimize the code, add more pages to NSPanel as done with e.g. LoveLace UI, etc.
This is the integration architecture I used
This is the integration architecture I used
Domoticz NSPanel integration.jpg (111.02 KiB) Viewed 2631 times
1. Flash NSPanel with latest Tasmota and correct settings, see the great work from Blakadder: https://templates.blakadder.com/sonoff_NSPanel.html
2. Add 10 virtual sensors (Switch type On/Off) in Domoticz - Switches:
  • NSPanel_1, e.g. idx101
    NSPanel_2, e.g. idx102

    NSPanel_Widget_1, e.g. idx1001
    NSPanel_Widget_2, e.g. idx1002
    NSPanel_Widget_3, e.g. idx1003
    NSPanel_Widget_4, e.g. idx1004
    NSPanel_Widget_5, e.g. idx1005
    NSPanel_Widget_6, e.g. idx1006
    NSPanel_Widget_7, e.g. idx1007
    NSPanel_Widget_8, e.g. idx1008
Added Virtual Switches
Added Virtual Switches
Domoticz NSPanel Switches_crop.jpg (173.15 KiB) Viewed 2631 times
For Widgets 1 to 8 = idx 1001 to 1008, add in Switches - NSPanel_Widget_# - Edit:

Code: Select all

        on-action: [url]http://<IPADDR>/cm?cmnd=nspsend%20{"ctype":"group","id":"n","params":{"switch":"on","switches":[{"switch":"on","outlet":0}]}}[/url]
        off-action: [url]http://<IPADDR>/cm?cmnd=nspsend%20{"ctype":"group","id":"n","params":{"switch":"off","switches":[{"switch":"off","outlet":0}]}}[/url]
with n = 1 to 8 and <IPADDR> is your local NSPanel IP-address
And you can enable “protected” if you like as you never will turn them on/off yourself
Switches - Edit - NSPanel_widget
Switches - Edit - NSPanel_widget
Domoticz widget settings.jpg (79.68 KiB) Viewed 2631 times
3. In NSPanel – Configuration – Domoticz fill in idx1 = 101 and idx2 = 102 to control the two HW buttons + relays
4. Add a rule in NSPanel – Console:

Code: Select all

Rule 1 on NSPanel#id<1 do Var1=1000+%value% break on NSPanel#id>8 do Var1=1000+%value% break on NSPanel#id do Var1=1000+%value% endon on NSPanel#params#switch=ON do Publish domoticz/in {"command": "switchlight", "idx": %Var1%, "switchcmd": "On"} endon on NSPanel#params#switch=OFF do Publish domoticz/in {"command": "switchlight", "idx": %Var1%, "switchcmd": "Off"} endon
Rule1 1 
Restart 1

5. Add two scripts to Domoticz (Dzvents):
- Script 1: Mirror Domoticz devices/groups with Domoticz NSPanel Widgets 1-8. If Dz device/group changes update Dz NSPanel widget and v.v.
- Script 2: Mirror Domoticz NSPanel Widgets state to NSPanel_Widgets every 2 minutes --> In case NSPanel is rebooted

Code: Select all

-- Script 1 to mirror Domoticz devices/groups with Domoticz NSPanel Widgets 1-8. If Dz device/group changes update Dz NSPanel widget and v.v.

return
{
    on =
        groups = {'Lights Living'},
        devices = {'NSPanel_1', -- Lights Living (HW button 1 on NSPanel)
                        'NSPanel_2', -- (HW button 2 on NSPanel)
                        'Light Kitchen', 'NSPanel_Widget_1', 'NSPanel_Widget_2', 'NSPanel_Widget_3', 'NSPanel_Widget_4', 'NSPanel_Widget_5', 'NSPanel_Widget_6', 'NSPanel_Widget_7', 'NSPanel_Widget_8'}
    },
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'NSPanel - Mirror states Dz_Devices and Dz_NSPanel_Widgets',
	},
    execute = function(domoticz, item)

            -- NSPanel_1: Lights Living
            if (item.isGroup and item.name == 'Lights Living' and item.state == 'Off' and domoticz.devices('NSPanel_1').state ~= 'Off') then -- mirror state from Dz_device/group to Dz_NSPanel Widget
                domoticz.log('Lights Living group Off so turn NSPanel_1 Off', domoticz.LOG_INFO)
                domoticz.devices('NSPanel_1').switchOff()
            elseif (item.isGroup and item.name == 'Lights Living' and item.state == 'On' and domoticz.devices('NSPanel_1').state ~= 'On') then -- mirror state from Dz_device/group to Dz_NSPanel Widget
                domoticz.log('Lights Living group On so turn NSPanel_1 On', domoticz.LOG_INFO)
                domoticz.devices('NSPanel_1').switchOn()

            elseif (item.isDevice and item.name == 'NSPanel_1' and item.state == 'Off' and domoticz.groups('Lights Living').state ~= 'Off') then -- mirror state from Dz_device/group to Dz_NSPanel Widget
                domoticz.log('NSPanel_1 Off so turn Lights Living group Off', domoticz.LOG_INFO)
                domoticz.groups('Lights Living').switchOff() -- domoticz group, not Hue
            elseif (item.isDevice and item.name == 'NSPanel_1' and item.state == 'On' and domoticz.groups('Lights Living').state ~= 'On') then -- mirror state from Dz_device/group to Dz_NSPanel Widget
                domoticz.log('NSPanel_1 On so turn Lights Living group On', domoticz.LOG_INFO)
                domoticz.groups('Lights Living').switchOn() -- domoticz group, not Hue
            else
                -- do nothing
            end

            -- NSPanel_2: todo
			
			
            -- Widget_1: Light Kitchen
            if (item.isDevice and item.name == 'Light Kitchen' and item.state == 'Off' and domoticz.devices('NSPanel_Widget_1').state == 'On') then -- mirror state from Dz_device/group to Dz_NSPanel Widget
                domoticz.log('Light Kitchen was turned Off so mirror Dz NSPanel_Widget_1', domoticz.LOG_INFO)
                domoticz.devices('NSPanel_Widget_1').switchOff()
            elseif (item.isDevice and item.name == 'Light Kitchen' and item.state ~= 'Off' and domoticz.devices('NSPanel_Widget_1').state == 'Off') then --  mirror state from Dz_device/group to Dz_NSPanel Widget
                domoticz.log('Light Kitchen was turned On so mirror Dz NSPanel_Widget_1', domoticz.LOG_INFO)
                domoticz.devices('NSPanel_Widget_1').switchOn()
            elseif (item.isDevice and item.name == 'NSPanel_Widget_1' and item.state == 'Off' and domoticz.devices('Light Kitchen').state ~= 'Off') then -- mirror state from Dz_NSPanel Widget to Dz_device/group 
                domoticz.log('Dz NSPanel_Widget_1 was turned Off so mirror Light Kitchen', domoticz.LOG_INFO)
                domoticz.devices('Light Kitchen').switchOff()
            elseif (item.isDevice and item.name == 'NSPanel_Widget_1' and item.state == 'On' and domoticz.devices('Light Kitchen').state == 'Off') then -- mirror state from Dz_NSPanel Widget to Dz_device/group
                domoticz.log('Dz NSPanel_Widget_1 was turned On so mirror Light Kitchen', domoticz.LOG_INFO)
                --domoticz.devices('Light Kitchen').switchOn()
            else
                -- do nothing
            end
 
            -- Widget_2: todo
            -- Widget_3: todo
            -- Widget_4: todo
            -- Widget_5: todo
            -- Widget_6: todo
            -- Widget_7: todo
            -- Widget_8: todo

    end -- execute
}

Code: Select all

--Script 2 to mirror Domoticz NSPanel Widgets state to NSPanel_Widgets every 2 minutes --> In case NSPanel is rebooted
return {
	on = {
		timer = {

			'every 2 minutes',
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'NSPanel - Mirror states Dz_NSPanel_Widgets to NSPanel_Widgets',
	},
	execute = function(domoticz, timer)

        local NSPanel_Widgets =
        {
            'NSPanel_Widget_1', 'NSPanel_Widget_2', 'NSPanel_Widget_3', 'NSPanel_Widget_4', 'NSPanel_Widget_5', 'NSPanel_Widget_6', 'NSPanel_Widget_7', 'NSPanel_Widget_8',  --idx 1001 .. 1008
        }
        local function MirrorState(dv)
            local n = tonumber(dv.idx - 1000) -- as idx Dz widget = 1001, - 1008 = 1 = idx NSPanel Widget, etc.
            domoticz.log( 'The '.. dv.name ..' is set to ' .. domoticz.devices(dv.name).state, domoticz.LOG_INFO)

            -- Fill in NSPanel IP-address in <IPADDR>
            if (domoticz.devices(dv.name).state == 'Off') then -- off. Send http command to NSPanel Widgets to mirror state
                domoticz.openURL('http://<IPADDR>/cm?cmnd=nspsend%20{%22ctype%22:%22group%22,%22id%22:%22'.. n ..'%22,%22params%22:{%22switch%22:%22off%22,%22switches%22:[{%22switch%22:%22off%22,%22outlet%22:0}]}}')
            elseif (domoticz.devices(dv.name).state == 'On') then -- on. Send http command to NSPanel Widgets to mirror state
                domoticz.openURL('http://<IPADDR>/cm?cmnd=nspsend%20{%22ctype%22:%22group%22,%22id%22:%22'.. n ..'%22,%22params%22:{%22switch%22:%22on%22,%22switches%22:[{%22switch%22:%22on%22,%22outlet%22:0}]}}')
            end
        end
        -- domoticz.log('Mirror Widget script was triggered', domoticz.LOG_INFO)
        domoticz.devices().filter(NSPanel_Widgets).forEach(function(dv)
            MirrorState(dv)
        end)
end -- execute
}

Adapt the scripts with your specific information such as devices/groups to control, IP-address NSPanel, etc.
Later I also added a ‘PING NSPanel IPADDR’ to only read/write to NSPanel if it is online:
Domoticz – Setup – Hardware –> Add System Alive Checker (Ping), select NSPanel as Node and e.g. 300 sec Poll interval
In both scripts add after “execute = function(domoticz)”:

Code: Select all

local Ping_NS = domoticz.devices(‘Ping NSPanel’)
  if (Ping_NS.state == 'On') then
  -- Put all code here
  end 
This works for me so I hope it is of use to someone...
Last edited by Gingerpale on Monday 02 December 2024 17:46, edited 1 time in total.
Rpi4B,RFX433e,PiFace2, LCD, Hue bridge, Alexa (+TTS), HA-Bridge, Sonoff NSPanel, Sonoff RF (+IR) bridge, Nefit CV, Tasmota/MQTT, Enphase Solar, Smartmeter, Alarm I/F, H13726B Weather Station, CM180 Energy meter, Sonoff, KaKu, Tuya, Gledopto, AriLux,...
Gingerpale
Posts: 10
Joined: Wednesday 13 January 2016 16:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: NS Panel Sonoff With Tasmota and MQTT

Post by Gingerpale »

And finally I also "mirrored" my Central Heating system (Nefit in my case) to the NSPanel Thermostat Page (ATC - page 3) partly by adding on/off actions to Nefit devices and partly by DzVents script:

Code: Select all

-- script for updating NSPanel thermostat page with Nefit data
--[[
Temperature: --> sync with Temp Setpoint Nefit Easy Living (SET TEMP) or with Room Temperature Nefit Easy (IST TEMP) --> script
  "ATCExpect1":%d (sets temp in auto mode)
  "ATCExpect0":%d (sets temp in manual mode)  

ATC ON/OFF slider: "ATCENABLE":%b (0/1) --> link with Status Boiler Nefit Easy (if central heating or hot water active show ON else OFF --> script

Manual/Auto: "ATCMode":%b (0/1) --> sync with Clock Mode Nefit Easy
Add to Dz Switches - Clock Mode Nefit Easy:
  on-action: http://<IPADDR>/cm?cmnd=nspsend%20{"ATCMode":1}
 off-action: http://<IPADDR>/cm?cmnd=nspsend%20{"ATCMode":0}

H/C icon: {"HMI_ATCDevice":{"etype":"hot"}} or {"HMI_ATCDevice":{"etype":"cold"}} --> link with Nefit Hot Water (if Hot water tap active show "hot" else "cold")
Add to Dz Switches - Nefit Hot Water:
  on-action: http://<IPADDR>/cm?cmnd=nspsend%20{%22HMI_ATCDevice%22:{%22etype%22:%22hot%22}}
 off-action: http://<IPADDR>/cm?cmnd=nspsend%20{%22HMI_ATCDevice%22:{%22etype%22:%22cold%22}}
...with <IPADDR> is your local NSPanel IP-address
]]--

return {
	on = {
		timer = {'every minute'},
        
	logging = {level = domoticz.LOG_INFO, marker = 'Nefit-NSPanel',},
	execute = function(domoticz,device)

    local Ping_NS = domoticz.devices('Ping NSPanel')

    if (Ping_NS.state == 'On') then
    --  Code for Set temp
        local NefitSetTemp = tonumber(domoticz.devices('Temp Setpoint Nefit Easy Living').setPoint)
        local NST = domoticz.utils.round(NefitSetTemp,1) --round to 1 decimal
        domoticz.log('Update NSPanel with Nefit Set Temp = ' .. NST .. ' degrees ', domoticz.LOG_INFO)
        domoticz.openURL('http://<IPADDR>/cm?cmnd=nspsend%20{%22ATCExpect0%22:'.. NST ..',%22ATCExpect1%22:'.. NST ..'}')
    
    -- ATC ON/OFF slider: "ATCENABLE":%b (0/1)
        local ATC = domoticz.devices('Status Boiler Nefit Easy').state
        if (ATC == 'central heating' or ATC == 'hot water') then
            domoticz.openURL('http://<IPADDR>/cm?cmnd=nspsend%20{%22ATCEnable%22:1}')
            domoticz.log('central heating or hot water tap active', domoticz.LOG_INFO)
        else
            domoticz.openURL('http://<IPADDR>/cm?cmnd=nspsend%20{%22ATCEnable%22:0}')
            domoticz.log('central heating inactive', domoticz.LOG_INFO)
        end
    end
end
}
Rpi4B,RFX433e,PiFace2, LCD, Hue bridge, Alexa (+TTS), HA-Bridge, Sonoff NSPanel, Sonoff RF (+IR) bridge, Nefit CV, Tasmota/MQTT, Enphase Solar, Smartmeter, Alarm I/F, H13726B Weather Station, CM180 Energy meter, Sonoff, KaKu, Tuya, Gledopto, AriLux,...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest