esphome adding timestamp data to my mqtt broker - esphome

My goal is move my C++ scripts to yaml and use esphome. I´ve started with something easy, esp8266+dht22+mqtt, really easy, but if i want to add also the timestamp in addition to temperature and humidity. I guess to use lambda?, text_sensor?. Any help will be appreciated.
This is my code:
sensor:
- platform: dht
pin: D5
model: AM2302
temperature:
name: "temperature_test"
filters:
- multiply: 0.92
humidity:
name: "humidity_test"
id: tempdht22
update_interval: 10s
mqtt:
#discovery_prefix: esphome_test
broker: 192.168.1.185
id: mqtt_client

Related

Write to Yaml file based on excel

I've got an YAML file that contains information from a Powerbi file. we need to add some of the metadata like Tags (we're talking here about tens of dosens if not hundreds.
what I thought is to extract this in an excel - write it there and then inject it back to yaml.
Any way to do that automatically?
here's a sample:
processTime: 08-06-22
report:
reportId: 34lkn34l5k
reportVersion: '1'
reportDeveloper: dev1
reportDomain: ''
linkedDataset: dataset
filters:
filterId: Filtera1
table: DIM_E
column: CLIENT
type: Categorical
metadata:
label: Company
tags: []
filterId: Filter2
table: DIM_E
column: DEPARTMENT
type: Categorical
metadata:
label: Department
tags: []
pages:
pageId: ReportSection
displayName: test
visuals:
visualId: 9dc8
visualType: donutChart
measures: Headcount
columns: - EMPLO
title: Headcount
metadata:
label: ''
tags: []
domain: diversity
hierarchy: []

Forms aren't activated on rasa 2.0.2

Ok so I'm running Rasa 2.0.2 and whenever I try to activate my forms, rasa seems to fail loading them. I'm pretty sure that my code runs properly since it runs on rasa 2.7.0. Also note that through some threads that I read online I knew that older versions of rasa need the utters with a certain naming such as: "utter_ask_name" so I did that and also slots need to be named like this: "slot_date". So I used both of these methods but still came to no success.
Any help?
domain.yml:
version: "2.0"
intents:
- greet
- inform
- subscribe
- bot_challenge
- name
- age
- learn
- book demo
- describe
- describe more
- learn more
- learn less
- date
- time
- firstname
- lastname
- email
- country
- kai101
slots:
email1:
type: unfeaturized
influence_conversation: false
slot_date:
type: unfeaturized
influence_conversation: false
slot_time:
type: unfeaturized
influence_conversation: false
slot_firstname:
type: unfeaturized
influence_conversation: false
slot_lastname:
type: unfeaturized
influence_conversation: false
slot_email:
type: unfeaturized
influence_conversation: false
slot_country:
type: unfeaturized
influence_conversation: false
responses:
utter_greet:
- text: |
Hello & welcome to achatbotAgancy.com! Your one-stop shop to the world of chatbots.
How may I assist you?
buttons:
- title: "Learn about chatbots"
payload: '/learn'
- title: "What do you want your chatbot to do? In a few words describe the purpose of your chatbot:"
payload: '/describe'
- title: "Book a demo to test drive us"
payload: '/book demo'
utter_kuh:
- text: |
What is your email address?
utter_subscribed:
- text: |
Check your inbox at {email} in order to finish subscribing to the newsletter!
- text: You're all set! Check your inbox at {email} to confirm your subscription.
- text: You've been subscribed, the newsletter will be sent to {email} shotly.
utter_i_am_a_bot:
- text: |
I am a bot powered by RASA
utter_my_name:
- text: |
I am KAI The Chatbot
utter_my_age:
- text: |
I was made on June 2 2021 and I'm still being developed on a regular basis.
utter_learn:
- text: |
A chatbot is a software application used to conduct an on-line chat conversation via text or text-to-speech, in lieu of providing direct contact with a live human agent.
Did that answer help your question or do need more information?
buttons:
- title: "No thank you"
payload: '/learn less'
- title: "I am intrested in learning more"
payload: '/learn more'
utter_description:
- text: |
What do you want your chatbot to do? In a few words describe the purpose of your chatbot:
utter_description_reply:
- text: |
Ah yes, we can definitely help with that. May I book an appointment for you with one of my colleagues?
utter_book_demo:
- text: |
Sure. I will ask one of our humans to reach out. May I know:
utter_learn_more:
- text: |
A chatbot is a software application used to conduct an on-line chat conversation via text or text-to-speech, in lieu of providing direct contact with a live human agent.
Did that answer help your question or do need more information?
buttons:
- title: "No thank you"
payload: '/learn less'
- title: "I am intrested in learning more"
payload: '/learn more'
utter_learn_less:
- text: |
Ok great.Well, I am one message away. Don’t be shy.
utter_learn_more1:
- text: |
Sure, I am more than happy to book an appointment for you.
utter_ask_date:
- text: |
May I know the best date that works for you?
utter_ask_time:
- text: |
Great, and what time??
utter_ask_firstname:
- text: |
May I know your first name?
utter_ask_lastname:
- text: |
May I know your last name?
utter_ask_email:
- text: |
May I know your email address?
utter_ask_country:
- text: |
Which country are you in?
utter_done_requesting:
- text: |
Awesome Mr.{slot_firstname} {slot_lastname}, one of my colleagues will contact you shortly on your email {slot_email} to book an appointment on {slot_date} at {slot_time}
actions:
- '...'
- utter_greet
- utter_kuh
- utter_subscribed
- utter_i_am_a_bot
- utter_my_name
- utter_my_age
- utter_learn
- utter_description
- utter_description_reply
- utter_book_demo
- utter_learn_more
- utter_learn_less
- utter_learn_more1
- utter_ask_date
- utter_ask_time
- utter_ask_firstname
- utter_ask_lastname
- utter_ask_email
- utter_ask_country
- utter_done_requesting
forms:
informative_form:
required_slots:
slot_date:
- type: from_text
slot_time:
- type: from_text
slot_firstname:
- type: from_text
slot_lastname:
- type: from_text
slot_email:
- type: from_text
slot_country:
- type: from_text
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
forms.yml:
forms:
informative_form:
required_slots:
slot_date:
- type: from_text
slot_time:
- type: from_text
slot_firstname:
- type: from_text
slot_lastname:
- type: from_text
slot_email:
- type: from_text
slot_country:
- type: from_text
nlu.yml:
version: "2.0"
nlu:
- intent: greet
examples: |
- Hi
- Hey!
- Hallo
- Good day
- Good morning
- howdy
- intent: subscribe
examples: |
- I want to get the newsletter
- Can you send me the newsletter?
- Can you sign me up for the newsletter?
- Can I on your mailing list?
- intent: inform
examples: |
- My email is example#example.com
- random#example.com
- Please send it to anything#example.com
- Email is something#example.com
- intent: bot_challenge
examples: |
- Are you a bot?
- Am I talking to a human?
- is this a chatbot?
- is this a real person?
- you're a bot, aren't you
- intent: name
examples: |
- What's your name?
- What did they name you??
- what are you called?
- What should I call you ?
- intent: learn
examples: |
- Learn about chatbots
- intent: describe
examples: |
- What do you want your chatbot to do? In a few words describe the purpose of your chatbot:
- intent: describe more
examples: |
- I want my chatbot to
- I want it to do something
- I want it to be something
- I want it
- To do something
- want it to be something
- do something
- intent: book demo
examples: |
- Book a demo to test drive us
- intent: learn less
examples: |
- No, thank you.
- intent: learn
examples: |
- I am interested in learning more.
- intent: kai101
examples: |
- Ask me your questions.
- Ask me about the form.
- intent: date
examples: |
- May 31 1999
- 31/05/1999
- July 16 1978
- 16/07/1978
- January 4 1974
- 04/01/1974
- September 10 2003
- 10/09/2003
- intent: time
examples: |
- 3:00 PM
- 8:00 AM
- 16:00
- 8 in the morning
- 4 afternoon
- 12 in the morning
- 4 in the evening
- intent: firstname
examples: |
- Kareem
- Yehya
- Mariam
- Johnny
- Charbel
- Nour
- Hanin
- Hussein
- John
- intent: lastname
examples: |
- Aridi
- Abou Dargham
- Harfouch
- Abou Dagher
- Smith
- Malaeb
- intent: email
examples: |
- My email is example#example.com
- random#example.com
- Please send it to anything#example.com
- Email is something#example.com
- intent: country
examples: |
- Lebanon
- USA
- UAE
- Palestine
- Syria
- Iraq
- Kuwait
- United States
- United Arab Emirates
- Kuwait
- Bahrain
- Saudi Arabia
- germany
I have a few observations to kicktart finding the right answer:
could you please offer more context behind the problem you're facing? What command were you trying, what was the error stacktrace? It would be helpful if you could run rasa shell --debug and post the full debug log in your question.
if you specify the form in domain.yml, you don't need to have a separate forms.yml file as per the docs
if you specified influence_conversation property as false, you don't need to use type: unfeaturized particularly because this has been deprecated. Perhaps these should all be type: text?
how are you using the form in stories and rules? are you able to share the contents of these files too? The formbot example is a good guideline to follow.

Preserve structure of YAML with ruamel yaml

I've been using ruamel yaml to edit my YAML files and dump them back. I need help understanding how to keep the same structure as the original file has, because all I do is duplicate it, edit, and write it again.
For example, this is the original file:
ElasticLoadBalancingV2Listener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
LoadBalancerArn: !Ref ElasticLoadBalancingV2LoadBalancer
Port: !FindInMap [NLBPorts, Port1, Port]
Protocol: "TCP"
DefaultActions:
-
Order: 1
TargetGroupArn: !Ref ElasticLoadBalancingV2TargetGroup1
Type: "forward"
The new file doesn't look the same:
ElasticLoadBalancingV2Listener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
LoadBalancerArn: !Ref ElasticLoadBalancingV2LoadBalancer
Port: !FindInMap [NLBPorts, Port1, Port]
Protocol: "TCP"
DefaultActions:
- Order: 1
TargetGroupArn: !Ref ElasticLoadBalancingV2TargetGroup1
Type: "forward"
The biggest issue is that I used all sorts of tricks that ruamel has to fix this, but each time some different part of the yaml breaks.
This is my function:
def editEndpointServiceTemplate(endpoint_service_template_path):
yaml = YAML()
yaml.preserve_quotes = True
# yaml.compact(seq_seq=False, seq_map=False)
# yaml.indent(mapping=4, sequence=3, offset=0)
#Load yaml file
with open(endpoint_service_template_path) as fp:
data = yaml.load(fp)
#Edit the yaml
data['Description'] = "CloudFormation"
#Write new yaml file
with open(endpoint_service_template_path, 'w') as fp:
yaml.dump(data, fp)
As you can see with the commented commands, I tinkered around with the settings but couldn't find the sweet spot.
In this case it is obvious that your function did not produce the output you present
(different indent, missing word "CloudFormation"), but in general you should take care
in questions this is the same, and that your program is complete so that results can
more easily be reproduced.
ruamel.yaml does not have built in functions for all kinds of seldom seen format, but yours
is relatively close to the output using the method .indent(mapping=4, sequence=4, offset=2) and
transform by checking line by line.
As it is less likely that withing string scalars you have a sequence indicators followed by three spaces ("- ")
(which additionally would have to occur wrapped to be the first non-space on a line), you better do
.indent(mapping=4, sequence=4, offset=0) transform that:
import sys
import ruamel.yaml
yaml_str = """\
ElasticLoadBalancingV2Listener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
LoadBalancerArn: !Ref ElasticLoadBalancingV2LoadBalancer
Port: !FindInMap [NLBPorts, Port1, Port]
Protocol: "TCP"
DefaultActions:
-
Order: 1
TargetGroupArn: !Ref ElasticLoadBalancingV2TargetGroup1
Type: "forward"
"""
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=4, sequence=4, offset=0)
yaml.preserve_quotes = True
data = yaml.load(yaml_str)
data['Description'] = "CloudFormation"
def break_seq(s):
result = []
PAT = '- '
for line in s.splitlines():
ls_line = line.lstrip()
if ls_line.startswith(PAT):
line = line.replace(PAT, ' - \n' + ' ' * (line.index(PAT) + 4))
result.append(line)
return '\n'.join(result)
yaml.dump(data, sys.stdout, transform=break_seq)
which gives:
ElasticLoadBalancingV2Listener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
LoadBalancerArn: !Ref ElasticLoadBalancingV2LoadBalancer
Port: !FindInMap [NLBPorts, Port1, Port]
Protocol: "TCP"
DefaultActions:
-
Order: 1
TargetGroupArn: !Ref ElasticLoadBalancingV2TargetGroup1
Type: "forward"
Description: CloudFormation
The above can be done by "hacking" the routines that serialize to sequences, but
it is often easier to just transform the output, although not as efficient in
time/space usage.
Unless the program consuming this output uses an incomplete YAML parser, the
actual data structure loaded will not change, it is just less readable for people
unused to such uncommon formatting.

Storm-kafka: set startOffsetTime to kafka.api.OffsetRequest.LatestTime in apache Flux Yaml topology

I am working on a topology using apache flux. Currently, strom fetches messages from beginning but I want it to fetch only the latest messages from kafka.
I am writing topology in YAML file.
This is how my spoutConfig looks like:
- id: "stringScheme"
className: "org.apache.storm.kafka.StringScheme"
- id: "stringMultiScheme"
className: "org.apache.storm.spout.SchemeAsMultiScheme"
constructorArgs:
- ref: "stringScheme"
- id: "zkHosts"
className: "org.apache.storm.kafka.ZkHosts"
constructorArgs:
- "172.25.33.191:2181"
- id: "spoutConfig"
className: "org.apache.storm.kafka.SpoutConfig"
constructorArgs:
- ref: "zkHosts"
- "blockdata"
- ""
- "myId"
properties:
- name: "scheme"
ref: "stringMultiScheme"
- name: "ignoreZkOffsets"
value: true
- name: "startOffsetTime"
ref: "XXXXXXXXX"
Now, I am stuck. How do I set startOffsetTime to proper function to get only the latest messages from kafka?
I have tried ref:"LatestTime", but no matter what I put in there, it give me error :
java.lang.IllegalArgumentException: Can not set long field org.apache.storm.kafka.KafkaConfig.startOffsetTime to null value
I believe Flux can handle calling static factory methods.
- id: "startingOffsetTime"
className: "kafka.api.OffsetRequest"
factory: "LatestTime"
and then use it in your SpoutConfig definition like
properties:
- name: "startOffsetTime"
ref: "startingOffsetTime"
I haven't tested this, but I think it should work. The ability to call static factory methods was merged a while back https://issues.apache.org/jira/browse/STORM-2796, but it seems to be missing from the documentation. I've raised an issue to update the docs https://issues.apache.org/jira/browse/STORM-3086.
In case you'd like to see an example of this feature, take a look at https://github.com/apache/storm/blob/master/flux/flux-core/src/test/resources/configs/config-methods-test.yaml#L38

!ImportValue in Serverless Framework not working

I'm attempting to export a DynamoDb StreamArn from a stack created in CloudFormation, then reference the export using !ImportValue in the serverless.yml.
But I'm getting this error message:
unknown tag !<!ImportValue> in "/codebuild/output/src/serverless.yml"
The cloudformation and serverless.yml are defined as below. Any help appreciated.
StackA.yml
AWSTemplateFormatVersion: 2010-09-09
Description: Resources for the registration site
Resources:
ClientTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: client
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
Outputs:
ClientTableStreamArn:
Description: The ARN for My ClientTable Stream
Value: !GetAtt ClientTable.StreamArn
Export:
Name: my-client-table-stream-arn
serverless.yml
service: my-service
frameworkVersion: ">=1.1.0 <2.0.0"
provider:
name: aws
runtime: nodejs6.10
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
- dynamodb:GetItem
- dynamodb:PutItem
Resource: arn:aws:dynamodb:*:*:table/client
functions:
foo:
handler: foo.main
events:
- stream:
type: dynamodb
arn: !ImportValue my-client-table-stream-arn
batchSize: 1
Solved by using ${cf:stackName.outputKey}
I struggled with this as well, and what did trick for me was:
functions:
foo:
handler: foo.main
events:
- stream:
type: dynamodb
arn:
!ImportValue my-client-table-stream-arn
batchSize: 1
Note, that intrinsic functions ImportValue is on a new line and indented, otherwise the whole event is ignored when cloudformation-template-update-stack.json is generated.
It appears that you're using the !ImportValue shorthand for CloudFormation YAML. My understanding is that when CloudFormation parses the YAML, and !ImportValue actually aliases Fn::ImportValue. According to the Serverless Function documentation, it appears that they should support the Fn::ImportValue form of imports.
Based on the documentation for Fn::ImportValue, you should be able to reference the your export like
- stream:
type: dynamodb
arn: {"Fn::ImportValue": "my-client-table-stream-arn"}
batchSize: 1
Hope that helps solve your issue.
I couldn't find it clearly documented anywhere but what seemed to resolve the issue for me is:
For the Variables which need to be exposed/exported in outputs, they must have an "Export" property with a "Name" sub-property:
In serverless.ts
resources: {
Resources: resources["Resources"],
Outputs: {
// For eventbus
EventBusName: {
Export: {
Name: "${self:service}-${self:provider.stage}-UNIQUE_EVENTBUS_NAME",
},
Value: {
Ref: "UNIQUE_EVENTBUS_NAME",
},
},
// For something like sqs, or anything else, would be the same
IDVerifyQueueARN: {
Export: {
Name: "${self:service}-${self:provider.stage}-UNIQUE_SQS_NAME",
},
Value: { "Fn::GetAtt": ["UNIQUE_SQS_NAME", "Arn"] },
}
},
}
Once this is deployed you can check if the exports are present by running in the terminal (using your associated aws credentials):
aws cloudformation list-exports
Then there should be a Name property in a list:
{
"ExportingStackId": "***",
"Name": "${self:service}-${self:provider.stage}-UNIQUE_EVENTBUS_NAME", <-- same as given above (but will be populated with your service and stage)
"Value": "***"
}
And then if the above is successful, you can reference it with "Fn::ImportValue" like so, e.g.:
"Resource": {
"Fn::ImportValue": "${self:service}-${self:provider.stage}-UNIQUE_EVENTBUS_NAME", <-- same as given above (but will be populated with your service and stage)
}