Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Du möchtest Deinen Automower in Deine Hausautomatisierung einbinden oder eine eigene App entwicklen?
Hier wird diese offene Schnittstelle zum Robonect Hx Modul beschrieben.
Mosvold
Beiträge: 17
Registriert: Fr 28. Jul 2017, 13:50
Wohnort: Norwegen
Mäher: Husqvarna Automower 430X
Firmware des Mähers (MSW): MSW 7.xx.xx
Herstellungsjahr: 2016
Robonect-Modul: Robonect Hx (Rev.4)
Robonect Firmware: 1.0

Re: Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Beitrag von Mosvold » Sa 29. Jul 2017, 12:24

Thanks for your reply MSAN :)

May I assume that my problem is related to that I am running on wheezy and not jessy ?

Code: Alles auswählen

pi@raspberrypi ~ $ uname -m
armv7l
pi@raspberrypi ~ $ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_0.10 wheezy main
deb-src https://deb.nodesource.com/node_0.10 wheezy main
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 4.4.14-v7+ #896 SMP Sat Jul 2 15:09:43 BST 2016 armv7l GNU/Linux
pi@raspberrypi ~ $ 
I may have to read about moving to newer versions..
OleG

Mosvold
Beiträge: 17
Registriert: Fr 28. Jul 2017, 13:50
Wohnort: Norwegen
Mäher: Husqvarna Automower 430X
Firmware des Mähers (MSW): MSW 7.xx.xx
Herstellungsjahr: 2016
Robonect-Modul: Robonect Hx (Rev.4)
Robonect Firmware: 1.0

Re: Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Beitrag von Mosvold » Sa 29. Jul 2017, 17:23

Mosvold hat geschrieben:
Sa 29. Jul 2017, 12:24
Thanks for your reply MSAN :)

May I assume that my problem is related to that I am running on wheezy and not jessy ?

Code: Alles auswählen

pi@raspberrypi ~ $ uname -m
armv7l
pi@raspberrypi ~ $ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_0.10 wheezy main
deb-src https://deb.nodesource.com/node_0.10 wheezy main
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 4.4.14-v7+ #896 SMP Sat Jul 2 15:09:43 BST 2016 armv7l GNU/Linux
pi@raspberrypi ~ $ 
I may have to read about moving to newer versions..
Update: I have a raspi3 with Jessie and it works okay there.
I have to move every devices to this new hardware. Such a huge job! :x I cannot find a easy way to move zwave to a new controller other than exclude from old and include to new.
OleG

msan
Beiträge: 19
Registriert: Fr 12. Mai 2017, 12:30
Wohnort: Sweden
Mäher: Husqvarna Automower 420
Firmware des Mähers (MSW): MSW 7.xx.xx
Herstellungsjahr: 2016
Robonect-Modul: Robonect Hx (Rev.3)
Robonect Firmware: V1.0 Beta 3

Re: Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Beitrag von msan » Sa 29. Jul 2017, 19:14

Mosvold hat geschrieben:
Sa 29. Jul 2017, 17:23
Mosvold hat geschrieben:
Sa 29. Jul 2017, 12:24
Thanks for your reply MSAN :)

May I assume that my problem is related to that I am running on wheezy and not jessy ?

Code: Alles auswählen

pi@raspberrypi ~ $ uname -m
armv7l
pi@raspberrypi ~ $ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_0.10 wheezy main
deb-src https://deb.nodesource.com/node_0.10 wheezy main
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 4.4.14-v7+ #896 SMP Sat Jul 2 15:09:43 BST 2016 armv7l GNU/Linux
pi@raspberrypi ~ $ 
I may have to read about moving to newer versions..
Update: I have a raspi3 with Jessie and it works okay there.
I have to move every devices to this new hardware. Such a huge job! :x I cannot find a easy way to move zwave to a new controller other than exclude from old and include to new.
node-robonect-api doesn't have to run at the same host that you have Domoticz on. Just install it on the Jessie host. You can probably also install a newer version of Node-JS on your wheezy host but I have never tried that. Besides there might be other benefits from upgrading your wheezy host anyway ;)

Cheers!

Mosvold
Beiträge: 17
Registriert: Fr 28. Jul 2017, 13:50
Wohnort: Norwegen
Mäher: Husqvarna Automower 430X
Firmware des Mähers (MSW): MSW 7.xx.xx
Herstellungsjahr: 2016
Robonect-Modul: Robonect Hx (Rev.4)
Robonect Firmware: 1.0

Re: Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Beitrag von Mosvold » So 30. Jul 2017, 14:18

msan hat geschrieben:
Sa 29. Jul 2017, 19:14
node-robonect-api doesn't have to run at the same host that you have Domoticz on. Just install it on the Jessie host. You can probably also install a newer version of Node-JS on your wheezy host but I have never tried that. Besides there might be other benefits from upgrading your wheezy host anyway ;)

Cheers!
It was that kick in my ass to make me do the job and move to raspi3 :lol: . Job done. :!:
Now I can keep playing again :-)

I have not read too much about the API.
Is it possible to send operation mode commands using JSON to Robonect? :?: (Such as Start, End of day, Home, etc)

Thanks.
OleG

msan
Beiträge: 19
Registriert: Fr 12. Mai 2017, 12:30
Wohnort: Sweden
Mäher: Husqvarna Automower 420
Firmware des Mähers (MSW): MSW 7.xx.xx
Herstellungsjahr: 2016
Robonect-Modul: Robonect Hx (Rev.3)
Robonect Firmware: V1.0 Beta 3

Re: Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Beitrag von msan » So 30. Jul 2017, 15:12

I'm happy to hear that! :D
Mosvold hat geschrieben:
So 30. Jul 2017, 14:18
Is it possible to send operation mode commands using JSON to Robonect? :?: (Such as Start, End of day, Home, etc)
It's quite off topic but you can control the mower from Domoticz by letting Domoticz open an URL. See Übersicht aller implementierten Kommandos.

Below is a Domoticz dzVents script. (Minimum dzVents version is 2.2.0). It can serve as an example of what you can do. If You have further questions about dzVents or the script, it's better to ask them at the Domoticz forum.

Good luck!

Code: Alles auswählen

--[[
glenn.lua by BakSeeDaa
dzVents Lawn Mower script 
Version 1.1.1
--]]

local MOWER_NAME = 'Glenn'
local STATUS_DETERMINING = 'Status is determined'
local STATUS_PARKED = 'Parked'
local STATUS_MOWING = 'Mowing'
local STATUS_LOOKING = 'Seeking charging station'
local STATUS_LOADING = 'Charging'
local STATUS_SEARCHING = 'Moving to lawn mowing area'
local STATUS_ERROR = 'Error'
local STATUS_LOST_SIGNAL = 'Circuit error'
local STATUS_SWITCHED_OFF = 'Turned off'
local STATUS_SLEEPING = 'Sleeping'

local STATUS_MODE_AUTO = 'Auto'
local STATUS_MODE_MAN = 'Manuell'
local STATUS_MODE_HOME = 'Hem'
local STATUS_MODE_DEMO = 'Demo'

local TIMER_STATUS_DISABLED = 'Inactive'
local TIMER_STATUS_ACTIVE = 'Active'
local TIMER_STATUS_STAND_BY = 'Waiting'

local MOWER_URL = 'http://USERNAME:PASSWORD@MYMOWERHOST:80/'

return {
	active = true,
	logging = {
		--level = domoticz.LOG_DEBUG, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level
		marker = "glenn"
	},
	on = {
		devices = {
			'Glenn Sensor', -- The alarm sensor
			'Glenn Status', -- Main status
			'Glenn Mode', -- Operating mode
			'Glenn Timer Status', -- Timer Status
			'Glenn Battery Level',
		},
		timer = {
			'every 15 minutes'
		}
	},
	data = {
		lastFeierAbend = { history = true, maxItems = 1 }
  },

	execute = function(domoticz, device, triggerInfo)
    local MOWER_STATUS_DEVICE = domoticz.devices('Glenn Status')
    local MOWER_ALARM_DEVICE = domoticz.devices('Glenn Sensor')

		-- Init data if missing (e.g. the first time that the scripts runs)
		if (domoticz.data.lastFeierAbend.size == 0) then domoticz.data.lastFeierAbend.add('Init') end


		if triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then

			if device.name == 'Glenn Force Mowe until 13:30 and then quit for the day' then
				-- See http://robonect.de/viewtopic.php?f=10&t=37
				if device.state == 'On'
				and (domoticz.devices('Glenn Timer Status').state ~= TIMER_STATUS_ACTIVE) then
					local url = MOWER_URL..'job?begin=0&end=1497031200&fs=0&corridor=255&after=3&save=1'
					domoticz.sendCommand('OpenURL', url)
				else
					-- local url = MOWER_URL..'json?cmd=mode&mode=auto'
					-- domoticz.sendCommand('OpenURL', url)
				end
			end

			-- Sync dl4b Glenn
			-- We need Glenn Sensor to conditionally switch dl4b Glenn because lawn mowing may occur when we are not at home or sleeping
			if device == MOWER_ALARM_DEVICE then
				if device.state == 'On'
				and (domoticz.devices('Glenn Timer Status').state == TIMER_STATUS_STAND_BY) then
					if (domoticz.devices('dl4b Glenn').state ~= 'On') then domoticz.devices('dl4b Glenn').switchOn() end
				else
					if (domoticz.devices('dl4b Glenn').state ~= 'Off') then domoticz.devices('dl4b Glenn').switchOff() end
				end
			end

			if device.name == 'Glenn Status' then
				local event = 'Robotklipparen Glenn'
				local description = ''
				local priority = -2

				if (device.state == STATUS_SEARCHING) then
					if domoticz.devices('Glenn Timer Status').state == TIMER_STATUS_ACTIVE then
						-- The robot is scheduled for activity and allowed to go out ...
						description = MOWER_NAME..' will begin mowing the lawn.'
					else
						-- The robot is working outside it's schedule ...	
						description = MOWER_NAME..' working late hours'
					end
				elseif (device.state == STATUS_LOOKING) then
					if (domoticz.devices('Glenn Timer Status').state == TIMER_STATUS_ACTIVE)
					or (domoticz.devices('Glenn Timer Status').state == TIMER_STATUS_DISABLED) then
						-- The robot is scheduled for activity and allowed to go out and in...
						-- or returning from a job outside it's normal schedule
						description = MOWER_NAME..' is docking for recharging the batteries.'
					elseif domoticz.devices('Glenn Timer Status').state == TIMER_STATUS_STAND_BY then
						-- The robot has finished a job within it's normal schedule ...
						description = MOWER_NAME..' is crawling back to his shed and finishes his job for this day.'
					end
				end

				if description ~= '' then
					domoticz.helpers.sendNotification(event, description, priority)
					if (priority == 0) then
						domoticz.helpers.speak(domoticz.security, description, '', 1)
					else
						domoticz.helpers.speak(domoticz.security, description)
					end
				end

			end

		elseif triggerInfo.type == domoticz.EVENT_TYPE_TIMER then

			if (MOWER_STATUS_DEVICE.state == STATUS_MOWING
			or MOWER_STATUS_DEVICE.state == STATUS_LOOKING
			or MOWER_STATUS_DEVICE.state == STATUS_SEARCHING
			or MOWER_STATUS_DEVICE.state == STATUS_ERROR)
			and MOWER_STATUS_DEVICE.lastUpdate.minutesAgo > 133 then
				-- Glenn has been out for too long. Where is he?
				local event = 'Robotklipparen '..MOWER_NAME
				local description = MOWER_NAME..' has been out for too long . Is he drunk or what?'
				local priority = 0
				domoticz.helpers.speak(domoticz.security, description, '', 1)
				domoticz.helpers.sendNotification(event, description, priority)
			end

			if domoticz.time.hour > 9 and domoticz.time.hour < 17
			and domoticz.devices('WH2600 Rain').rainRate > 0.015
			and domoticz.data.lastFeierAbend.getLatest().time.hoursAgo > 12
			and domoticz.devices('Glenn Mode').state == STATUS_MODE_AUTO then
				domoticz.data.lastFeierAbend.add()
				local message = 'Oh no, it\'s raining. '..MOWER_NAME..' gets the rest of the day off.'
				domoticz.log(message, domoticz.LOG_INFO)
				domoticz.helpers.speak(domoticz.security, message)
				local url = MOWER_URL..'json?cmd=mode&mode=eod'
				domoticz.sendCommand('OpenURL', url)
			end

		end
	end
}

Mosvold
Beiträge: 17
Registriert: Fr 28. Jul 2017, 13:50
Wohnort: Norwegen
Mäher: Husqvarna Automower 430X
Firmware des Mähers (MSW): MSW 7.xx.xx
Herstellungsjahr: 2016
Robonect-Modul: Robonect Hx (Rev.4)
Robonect Firmware: 1.0

Re: Using a node.js module (node-robonect-api) for accessing robonect events in a Home Automation Scenario

Beitrag von Mosvold » So 30. Jul 2017, 16:14

Thanks a lot. A lot to look at now.
OleG

Antworten

Zurück zu „API für Robonect® Hx“