Node-RED automation for adjusting lighting or fan speed based on temperature

I have a function where I am retrieving temperature values from a sensor. I want to be able to turn something On or Off that is connected to a Raspberry Pi pin using a toggle switch. I tried using an if-else statement in the function, but it didn't return a Boolean value.

Answer №1

Perhaps this sequence could be beneficial for you... :)

node-red flow overview

[{"id":"b91e3004.20d918","type":"inject","z":"96584deb.e06cd8","name":"temperature = 5","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":480,"wires":[["8ed1e022.82aef8","90a9aef0.51dda"]]},{"id":"8ed1e022.82aef8","type":"function","z":"96584deb.e06cd8","name":"temp >= 10","func":"\nmsg.payload = (msg.payload >= 10);\n\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":460,"wires":[["b639cd87.885478","e13b38f4.0af918"]]},{"id":"b639cd87.885478","type":"debug","z":"96584deb.e06cd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":440,"wires":[]},{"id":"c44cdc90.fc2388","type":"inject","z":"96584deb.e06cd8","name":"temperature = 20","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":540,"wires":[["8ed1e022.82aef8","90a9aef0.51dda"]]},{"id":"e13b38f4.0af918","type":"rpi-gpio out","z":"96584deb.e06cd8","name":"","pin":"7","set":"","level":"0","freq":"","out":"out","x":650,"y":480,"wires":[]},{"id":"90a9aef0.51dda","type":"switch","z":"96584deb.e06cd8","name":"temp >= 10","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"10","vt":"str"},{"t":"lt","v":"10","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":560,"wires":[["72eff73c.7845b"],["268e12dd.9e100e"]]},{"id":"72eff73c.7845b","type":"template","z":"96584deb.e06cd8","name":"true","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"true","output":"str","x":650,"y":540,"wires":[["28a0b8f8.67062"]]},{"id":"28a0b8f8.67062","type":"rpi-gpio out","z":"96584deb.e06cd8","name":"","pin":"7","set":"","level":"0","freq":"","out":"out","x":790,"y":560,"wires":[]},{"id":"268e12dd.9e100e","type":"template","z":"96584deb.e06cd8","name":"false","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"false","output":"str","x":650,"y":580,"wires":[["28a0b8f8.67062"]]}]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Passing data from a child component to a parent component using Vue's emit

offspring template: ` <li v-for="option in listaOptiuni" :key="option.id"> <input @change="updateSelectAllToateOptiunile(); sendListaToateOptiunile()" v-model="listaToateOptiunile" :value="o ...

JQuery scroll position, floating menu bar, and animation delay

I'm in the process of creating a menu bar using JQuery, and I am a beginner with this technology. My goal is to have the menu bar delay when scrolling down, but stick immediately to the top of the browser window when scrolling up. Currently, the delay ...

What is the best way to serialize data from non-form elements and make it easily accessible through params[:model]?

I have developed a unique Sinatra application that leverages an external API to load data and exhibit it on a page. Utilizing Sinatra, the information is retrieved and stored in a temporary model instance (which is NOT saved) for seamless access to all its ...

Using JavaScript to detect the Facebook like button on a webpage

I am currently developing an application for Facebook using HTML and Javascript. My goal is to be able to detect when a user clicks the "Like" button on my company's Facebook page without needing to embed a separate "Like" button within my app itself. ...

Understanding the Process of Accessing Array Values in Immutable.js

I'm feeling a little puzzled and struggling to figure this out. Let's say I have the following code: const AnObj = Immutable.Map({ a : "a", b : Immutable.List.of( a, b, c, Immutable.Map({ a : "a" }) ) }); When working with Immu ...

Ways to retrieve HTML tags from a website's DOM and shadowDOM

I am currently working on a project using NodeJS where I need to extract the HTML structure of multiple websites. However, I am facing some challenges with this task. My goal is to retrieve only the HTML structure of the document without any content. It is ...

Material-ui Text Field

Is there anyone who can assist me in converting a TextField to a TextArea using the material-ui library? I am unable to find the parameter needed to personalize it as a TextArea: https://github.com/callemall/material-ui/blob/v1-beta/src/TextField/TextField ...

Why is req.body coming back as undefined?

I recently installed body-parser using npm, included it in my project with Express, but I'm still encountering the issue of req.body being undefined. If anyone can identify what's causing this problem, please share your insights as I suspect it m ...

Altering the playback of a flash object using HTML or JavaScript

Can the playback speed of a flash object be adjusted without recompiling the object, like through HTML attributes or JavaScript? Appreciate any help in advance ...

A plethora of unhandled DOMException errors found in a basic Vue.js application

I have been working on a Vue.js project for learning purposes, incorporating Quasar and Vuex. However, I keep encountering numerous Uncaught (in promise) DOMException errors which appear in the console. The application seems to work fine, but these red err ...

Facing a completely empty page after upgrading to vuejs 2.0

For me, upgrading my application to 2.0 has proven to be quite a challenge and I've spent hours trying to figure it out. In the past, I used vuejs within my application for certain functionalities, without treating it as a standalone vuejs application ...

Creating personalized functions in Object.prototype using TypeScript

My current situation involves the following code snippet: Object.prototype.custom = function() { return this } Everything runs smoothly in JavaScript, however when I transfer it to TypeScript, an error surfaces: Property 'custom' does not ex ...

Tips for enhancing Chevrotain within VRMLLoader

Currently facing an issue with loading vrml files into a three.js scene using the VRMLLoader bundled with three. While everything works smoothly when running the project locally, encountering a failure in the onLoad function when loading from a built depl ...

Sending information from Node.js to the backend using AJAX involves a seamless communication process

I'm relatively new to working with AJAX, so please excuse any misunderstandings I may have. I am still in the process of learning. My current task is quite simple. I have a backend file named server.js, an index.html file, and a script.js file. It&ap ...

Is it necessary for me to install node and npm in order to use bower, even if I am not a node programmer?

As a Java programmer focusing on a web application, I'm finding that managing JavaScript can be quite challenging. I recently discovered Bower, a JavaScript dependency manager, but found out that it requires both Node and npm to be installed first. ...

JavaScript functions do not work within the HTML code

I am currently working on my debut website and I'm facing an issue with the JavaScript file not functioning properly. Is there a chance you can help me troubleshoot this? I'm still in the learning stages of programming. This is the HTML content ...

How can I resolve the issue of the mouse x/y glitch while drawing on an HTML canvas using JavaScript/jQuery?

I've been searching all over for a solution to this issue, but I just can't seem to find out what's causing the problem... This is my first attempt at working on something like this in my spare time. I hope to apply what I learn to create a ...

Encountering errors when importing a JS file into a Vue project

I recently attempted to utilize the plugin https://www.npmjs.com/package/mobius1-selectr After running npm install mobius1-selectr I proceeded to import it into my main.js import 'mobius1-selectr/dist/selectr.min.css'; import 'mobius1-sel ...

Having trouble displaying options in VueJS Component using datalist

Currently, I am harnessing the power of VueJS and its components to create an extensive array of datalists and selectors, each equipped with a submit button for validation upon form submission. Initially, I successfully implemented a datalist within a com ...

Modifying the onclick function for a bootstrap glyphicon

How can I swap the .glyphicon-menu-down to glyphicon-menu-up when a user clicks on a link? Currently, it's not working as expected. Could there be an issue with my jQuery implementation? Markup <a data-toggle="collapse" data-parent="#accordion" h ...