Node Red Experiences

Hey, Guys. As well as helping out in this thread (above) I thought I’d also do a bit of shameless self-promoting by linking to my HA/Node-RED playlist on YouTube.
I know that a few people on here have been wondering about installing Node-RED so this may help. The channel is newish and not as exciting as @DrZzs (yet :wink: ) but the videos are getting better video after video.

Home Assistant & Node-RED YouTube Playlist

3 Likes

Subscribed :slight_smile:

1 Like

Hi @HassCasts, thanks for your help…
With the function that you sent the looping still happens, after a few more debugs I finded out that the service call enter in the same condition that the “login failed”… so I added a new switch with the condition msg.payload.event.domain = persistent_notification.

PS: Subscribed :grinning:

1 Like

Hi guys,
can someone please help me to implement these conditions in Node Red?

    - condition: or
    conditions:
    - condition: template
      value_template: '{{ states.media_player.kodi.attributes.media_content_type == "tvshow" }}'
    - condition: template
      value_template: '{{ states.media_player.kodi.attributes.media_content_type == "movie" }}'

When I put this {{ states.media_player.kodi.attributes.media_content_type == "tvshow" }} into the template and then add a switch, no data is being passed.

Hi Flagun,

I don’t use the media player component but I have solved a similar problem with the climate component.

What you could try in node red is to add the event state node on “media_player.kodi” then link it to the change node setup to set msg.payload to data.new_state.attributes.media_content_type.

Now you should have a msg that the payload is media_content_type that you can add a switch node on to check if the payload == tvshow or movie.

Let me know if this works for you!

Drop the “==”,

I did something basic like this. Make sure you change the url and password

[{"id":"a64591bd.ed215","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"2df496fc.47664a","type":"inject","z":"a64591bd.ed215","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262.1909942626953,"y":433.87501525878906,"wires":[["dbd1f3cb.f3c1"]]},{"id":"dbd1f3cb.f3c1","type":"api-render-template","z":"a64591bd.ed215","name":"Template","server":"d5ce5cec.92bc8","template":"{{ states.media_player.kodi_lounge.attributes.media_content_type }}","x":466.1909942626953,"y":436.17362213134766,"wires":[["943c7096.70aeb"]]},{"id":"943c7096.70aeb","type":"switch","z":"a64591bd.ed215","name":"Parse","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"tvshow","vt":"str"},{"t":"eq","v":"movie","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":638.1875152587891,"y":436.46875762939453,"wires":[["a60cec1.904141"],["31703fbd.861b5"]]},{"id":"a60cec1.904141","type":"debug","z":"a64591bd.ed215","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":801.1909942626953,"y":393.2222366333008,"wires":[]},{"id":"31703fbd.861b5","type":"debug","z":"a64591bd.ed215","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":796.0173416137695,"y":479.01041412353516,"wires":[]},{"id":"d5ce5cec.92bc8","type":"server","z":"","name":"Home Assistant","url":"https://localhost:8123","pass":"password"}]

Thanks guys I will try it out soon.

So I spent way too long today trying to figure out how to model a state trigger with a “for” element, e.g., I have an automation to turn off my printer’s smart switch if the power reading has been below 19 watts for an hour:

- alias: Turn printer off if idle
    trigger:
      platform: numeric_state
      entity_id: sensor.printer_power
      below: 19
      for:
        hours: 1
    action:
      ...

After much trial and mostly error, ended up with the following:

The “printer” state node publishes the current power level and the switch node routes based on whether below or above 19 watts. The delay node will wait for an hour to make sure we have stopped using the printer. The change node will reset things if a new active power message come in. I feedback the first idle message through the delay to to remove any queued up idle power messages still in the delay node. I then double-check that the printer hasn’t already been turned-off in the mean time before firing the service call.

Appreciate any thoughts and maybe of use to others.

You could use a stoptimer node for this exact use case. The stoptimer will start after it receives a message. If it receives a message before the timer ends it will restart. If the timer runs out it goes through with the message and turns off your printer.

I found that you can replicate the stoptimer node by using the built in trigger node, this should also meet the requirements of PeteB

2 Likes

I’ve only been using Node Red for 2 weeks, but I was impressed enough to make all the devs in my team watch the first video on the website. And a big shout-out to @hasscasts for the youtube on the easiest way to get started. I wouldn’t be using Home Assistant without that video and Node Red, because text-based Automations etc makes my head hurt.

Having said that, parts of Node Red feel a bit unrealiable, although it’s probably my inexperience and generally I’ve been able to work around it with what ends up being a better solution anyway. For example, I have a heater controlled by a Broadlink RM2 IR blaster. I wanted it to come on in the morning if it’s cold outside, and switch off at various times of the day (if turned on manually). I didn’t get a lot of confidence from the community schedulers because they didn’t always seem to fire reliably. I ended up using Light Scheduler set to ‘minutely’ followed by an rbe to filter down to changes only.

I could then turn the heater on and off, but since Debug seems to stop working, it was still hard to feel confident, so I added in PushBullet. And while I could inject to confirm the PushBullet worked, when it followed the service call, it never worked. (Is this a known problem?)

This is when I learnt an important lesson - make everything an event. Since the RM2 doesn’t have a state that can cause a trigger, I created an input_boolean for the heater, and just set it to ‘on’ when I want the heater on. Another sequence then starts to actually turn it on or off, and yet another sequence starts to send the PushBullet. It results in more granular flows that are easier to test.

I’m trying to set a value in my payload by reading a value from the message object. I’m reading a string, but it seems I can’t paste it into the “entity_id” parameter:



if I try to store {{ bri }} (which is a number, in this case 100) it works fine… any thoughts?

try this

{ "data": { "entity_id": "{{device_name}}" } }

By the way, whats the purpose of quotes here? Is it like it casts the value to a string?

unless is boolean or number, all strings need to be quoted in json.

can you tell me how to debug automations, or give a link, I can’t get it …

can you please share your code, trying to do something similar

amazing how much idle power is consumed by electronics in the house … I am trying to put smart sockets (with power reading) EVERYWHERE in the house

can you share the code? thanks

you use the ‘DEBUG’ node and attach it anywhere you need to debug…