<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lambda-Funktion &#8211; SmartHomeNG | smarthome knx homematic mqtt hue 1wire home automation</title>
	<atom:link href="https://www.smarthomeng.de/tag/lambda-funktion/feed" rel="self" type="application/rss+xml" />
	<link>https://www.smarthomeng.de</link>
	<description>Die Device Integrations-Plattform für Dein Smart Home</description>
	<lastBuildDate>Sun, 29 Mar 2020 09:11:14 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.5</generator>

<image>
	<url>https://www.smarthomeng.de/wp-content/uploads/global/logo_small_152x152-150x150.png</url>
	<title>Lambda-Funktion &#8211; SmartHomeNG | smarthome knx homematic mqtt hue 1wire home automation</title>
	<link>https://www.smarthomeng.de</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>AWS für das Alexa Plugin einrichten</title>
		<link>https://www.smarthomeng.de/aws-fuer-das-alexa-plugin-einrichten</link>
					<comments>https://www.smarthomeng.de/aws-fuer-das-alexa-plugin-einrichten#comments</comments>
		
		<dc:creator><![CDATA[Marc René Frieß]]></dc:creator>
		<pubDate>Thu, 29 Nov 2018 17:15:15 +0000</pubDate>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Alexa]]></category>
		<category><![CDATA[alexa4p3]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Lambda-Funktion]]></category>
		<guid isPermaLink="false">https://www.smarthomeng.de/?p=2207</guid>

					<description><![CDATA[Mit dem Alexa Plugin ist es möglich, SmartHomeNG Items über Alexa zu steuern. Um das Plugin einzurichten, müssen allerdings zuerst einige Dinge auf der Plattform Amazon Web Services (AWS) eingerichtet werden. Dieser Artikel ist Work in Progress und wird nach und nach die Alexa Doku im README des Plugins und<a class="moretag" href="https://www.smarthomeng.de/aws-fuer-das-alexa-plugin-einrichten"> Weiterlesen&#8230;</a>]]></description>
										<content:encoded><![CDATA[<p>Mit dem Alexa Plugin ist es möglich, SmartHomeNG Items über Alexa zu steuern. Um das Plugin einzurichten, müssen allerdings zuerst einige Dinge auf der Plattform Amazon Web Services (AWS) eingerichtet werden.</p>
<p>Dieser Artikel ist Work in Progress und wird nach und nach die Alexa Doku im <a href="https://github.com/smarthomeNG/plugins/tree/master/alexa" target="_blank" rel="noopener">README des Plugins</a> und im KNX-User-Forum (<a href="https://knx-user-forum.de/forum/supportforen/smarthome-py/1021150-amazon-alexa-plugin" target="_blank" rel="noopener">https://knx-user-forum.de/forum/supportforen/smarthome-py/1021150-amazon-alexa-plugin</a>) ablösen. Ein Teil der Originalanleitung war zudem unter <a href="https://developer.amazon.com/de/blogs/post/Tx4WG410EHXIYQ/Five-Steps-Before-Developing-a-Smart-Home-Skill" target="_blank" rel="noopener">https://developer.amazon.com/de/blogs/post/Tx4WG410EHXIYQ/Five-Steps-Before-Developing-a-Smart-Home-Skill</a> dokumentiert.</p>
<p>Zuerst muss unter <a href="https://developer.amazon.com/home.html" target="_blank" rel="noopener">https://developer.amazon.com/home.html</a> ein Entwicklerzugang erstellt werden. Trotz später notwendiger Angabe einer Kreditkarte kann davon ausgegangen werden, dass die anfallenden Request bei normaler Nutzung deutlich unterhalb der Grenze für die &#8222;Free Tier&#8220; bleiben werden. Trotzdem sollte man gelegentlich im Billing nachsehen. Auch ist zu empfehlen, den Zugang als 2-Factor-Authentifizierung einzurichten, anstatt das auch im &#8222;Shopping&#8220; Amazon verwendete Passwort alleine zu verwenden!</p>
<h1>OAuth2 Credentials anlegen</h1>
<p>Über <a href="https://developer.amazon.com/home.html" target="_blank" rel="noopener">https://developer.amazon.com/home.html</a> &#8211;&gt; &#8222;Login with Amazon&#8220; muss zuerst via &#8222;Create a New Security Profile&#8220; ein neues Security Profile erzeugt werden.</p>
<p><img fetchpriority="high" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/lws.jpg" alt="" width="1377" height="315" class="alignnone size-full wp-image-2219" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/lws.jpg 1377w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lws-300x69.jpg 300w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lws-768x176.jpg 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lws-1024x234.jpg 1024w" sizes="(max-width: 1377px) 100vw, 1377px" /></p>
<p>Hier sind ein Name, eine Beschreibung und ein Link auf eine &#8222;privacy.htm&#8220; Seite (bspw. via Dyndns &#8211; die Seite muss meines Wissens nicht erreichbar sein) anzugeben.</p>
<p>Über den Reiter Web Settings kann man nun noch seine Client ID und seinen Client Secret einsehen, die für den nächsten Schritt notiert werden müssen. Im unten stehenden Screenshot sind die Informationen entfernt worden:</p>
<p><img decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/lws_clientdaten.png" alt="" width="1381" height="629" class="alignnone size-full wp-image-2220" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/lws_clientdaten.png 1381w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lws_clientdaten-300x137.png 300w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lws_clientdaten-768x350.png 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lws_clientdaten-1024x466.png 1024w" sizes="(max-width: 1381px) 100vw, 1381px" /></p>
<h1>Alexa Skill anlegen</h1>
<p>Als Nächstes muss im Alexa Entwicklerportal ein neuer Skill angelegt werden. Hierzu unter <a href="https://developer.amazon.com/alexa/console/ask" target="_blank" rel="noopener">https://developer.amazon.com/alexa/console/ask</a> &#8222;Create Skill&#8220; auswählen.</p>
<p><img decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_developer_overview.jpg" alt="" width="1304" height="601" class="alignnone size-full wp-image-2212" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_developer_overview.jpg 1304w, https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_developer_overview-300x138.jpg 300w, https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_developer_overview-768x354.jpg 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_developer_overview-1024x472.jpg 1024w" sizes="(max-width: 1304px) 100vw, 1304px" /></p>
<p>Hier ist die korrekte geographische Region als Default Endpoint zu wählen (in meinem Fall eu-west bzw. Europe/India). Als Payload ist für die alten Version des Plugins v2 zu wählen, für die aktuell in Entwicklung befindliche neue (derzeit noch nicht im DEV Branch, dafür unter <a href="https://github.com/Andrek01/Alexa4PayloadV3" target="_blank" rel="noopener">https://github.com/Andrek01/Alexa4PayloadV3</a>) v3.</p>
<p><img loading="lazy" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_skill.png" alt="" width="1369" height="1044" class="alignnone size-full wp-image-2213" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_skill.png 1369w, https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_skill-300x229.png 300w, https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_skill-768x586.png 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/alexa_skill-1024x781.png 1024w" sizes="(max-width: 1369px) 100vw, 1369px" /></p>
<p><strong>Wichtig:</strong> Das was neben &#8222;amzn1.ask.skill.&#8220; bei &#8222;<span>Your Skill ID&#8220; steht, kopieren. Diese UUID wird später für den nächsten Schritt (Lambda-Funktion) benötigt!</span></p>
<p>Unter Account Linking sind nun die OAuth2 Daten zu hinterlegen, die im vorherigen Schritt generiert wurden:</p>
<p><img loading="lazy" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/account_linking-1.png" alt="" width="1384" height="1278" class="alignnone size-full wp-image-2216" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/account_linking-1.png 1384w, https://www.smarthomeng.de/wp-content/uploads/2018/11/account_linking-1-300x277.png 300w, https://www.smarthomeng.de/wp-content/uploads/2018/11/account_linking-1-768x709.png 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/account_linking-1-1024x946.png 1024w" sizes="(max-width: 1384px) 100vw, 1384px" /></p>
<h1>Lambda-Funktion anlegen.</h1>
<p>Um Aktionen gegen SmartHomeNG ausführen zu können, muss über <a href="https://aws.amazon.com" target="_blank" rel="noopener">https://aws.amazon.com</a> (und dann in die AWS Management Console gehen) eine sog. Lambda-Funktion angelegt werden (Link Compute -&gt; Lambda).</p>
<p><img loading="lazy" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda.jpg" alt="" width="1157" height="681" class="alignnone size-full wp-image-2246" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda.jpg 1157w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-300x177.jpg 300w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-768x452.jpg 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-1024x603.jpg 1024w" sizes="(max-width: 1157px) 100vw, 1157px" /></p>
<p>Legt man diese über &#8222;Funktion erstellen&#8220; an, müssen ein Name (bspw. SmartHomeNGFunction), eine Laufzeitumgebung (Node.js 8.10) und eine Vorhandene Rollen (lambda_basic_execution) gewählt werden.</p>
<p>Der neu erstellten Lambda-Funktion wird nun ein Alexa Smart Home Skill zugeordnet. Klickt man diesen unter &#8222;Auslöser hinzufügen&#8220; an, so gibt man nun die Anwendungs-ID (die UUID aus dem vorherigen Schritt) ein! Der Auslöser wird als aktiviert gesetzt!</p>
<p>Das Ganze ist in unten stehendem Screenshot zu sehen.</p>
<p><img loading="lazy" decoding="async" src="https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-1.png" alt="" width="1348" height="3065" class="alignnone size-full wp-image-2251" srcset="https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-1.png 1348w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-1-132x300.png 132w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-1-768x1746.png 768w, https://www.smarthomeng.de/wp-content/uploads/2018/11/lambda-1-450x1024.png 450w" sizes="(max-width: 1348px) 100vw, 1348px" />Als Code muss folgendes eingetragen werden:</p>
<pre><code class="language-javascript">
/*
You need to specify the following environmental variables in the lambda function:
- SMARTHOME_HOST
		foobar.dyndns.tld
- SMARTHOME_PORT
		443 - endpoint must be https enabled!
- SMARTHOME_PATH
		'/'
- SMARTHOME_AUTH
		'user:password'
*/
exports.handler = function(event, context, callback) {
	var data = JSON.stringify(event)

	var options = {
		hostname: process.env.SMARTHOME_HOST,
		port: process.env.SMARTHOME_PORT,
		path: process.env.SMARTHOME_PATH,
		method: 'POST',
		auth: process.env.SMARTHOME_AUTH,
		headers: {
			'Content-Type': 'application/json',
			'Content-Length': Buffer.byteLength(data)
		}
	};

	var https = require('https');
	var req = https.request(options, (res) =&gt; {
		console.log(`HTTP ${res.statusCode}`);
		res.setEncoding('utf8');

		var responseData = '';
		res.on('data', (dataChunk) =&gt; {
		    responseData += dataChunk
		});
		res.on('end', () =&gt; {
			console.log('raw response:', responseData)

			var response = JSON.parse(responseData);
			if (res.statusCode == 200) {
				console.info('OK', JSON.stringify(response))
				callback(null, response);
			} else {
				console.error('Failed', JSON.stringify(response))
				callback('DependentServiceUnavailableError');
			}
		});
	});
	req.on('error', (e) =&gt; {
		console.error('request failed', e);
		callback(e);
	});

	console.log('requesting', data)
	req.write(data);
	req.end();
}
</code></pre>
<p>Unterhalb des Codeblocks sind nun noch die vier Variablen SMARTHOME_AUTH (im Stil &lt;user&gt;:&lt;passwort&gt;), SMARTHOME_HOST, SMARTHOME_PATH und SMARTHOME_PORT zu definieren. Wird ein ReverseProxy mit HTTPS verwendet (siehe bspw. <a href="https://www.smarthomeng.de/nginx-als-reverseproxy">im Artikel NGINX als ReverseProxy</a>), so sollte der User und das Passwort dort als Basic Authentication gesetzt werden. Der ReverseProxy muss in Folge dann eine Weiterleitung auf das SmartHomeNG Alexa Plugin (SmartHomeNG URL und Alexa Port) definieren. Port wäre in diesem Fall 443 (https) und URL die Dyndns URL über die das Heimnetzwerk erreichbar ist.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.smarthomeng.de/aws-fuer-das-alexa-plugin-einrichten/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
